473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trying To Invoke a WebService

I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is true?
I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET. How can I accomplish this?

Wayne

================= code ==============
<script language="Javascript">
<!--

var req;
var response;
var city;
var state;

function loadXMLDoc(url) {
// branch for native XMLHttpRequest object

if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state = response.getElementsByTagName('state')[0].firstChild.data;
alert(city);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" +
req.statusText);
}
}
}

function loadxml(form) {
loadXMLDoc('http://www.wengert.org/' +
'zipcodes.asmx/GetZip?z=' + document.forms[0].txtZIP.value);
}

//-->

</script>
Aug 13 '05 #1
4 4445
"Wayne Wengert" <wa***********@wengert.org> wrote in message
news:be********************@comcast.com...
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is true? I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET. How can I accomplish this?

Wayne

================= code ==============
<script language="Javascript">
<!--

var req;
var response;
var city;
var state;

function loadXMLDoc(url) {
// branch for native XMLHttpRequest object

if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state = response.getElementsByTagName('state')[0].firstChild.data;
alert(city);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" +
req.statusText);
}
}
}

function loadxml(form) {
loadXMLDoc('http://www.wengert.org/' +
'zipcodes.asmx/GetZip?z=' + document.forms[0].txtZIP.value);
}

//-->

</script>


I don't know about ASP.NET but this works for me:

<html>
<head>
<title>xml_zip.htm</title>
<script type="text/javascript">
var req;
var response;
var city;
var state;

function loadXMLDoc(url) {
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state =
response.getElementsByTagName('state')[0].firstChild.data;
alert(city + ", " + state);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" + req.statusText);
}
}
}

function loadxml() {
loadXMLDoc('http://www.wengert.org/zipcodes.asmx/GetZip?z=' +
document.forms[0].txtZIP.value);
}
</script>
</head>
<body>
<form>
<input type="text" name="txtZIP" size="5" maxlength="5" value="">
<input type="button" value="Lookup" onclick="loadxml()">
<br>City, State :
<input type="text" name="txtcity">
<input type="text" name="txtstate">
<br>
<textarea name="output" cols="100" rows="30"></textarea>
</form>
</body>
</html>
I changed your
function loadxml(form) {
to
function loadxml() {
as well as the indentation for (my) readability.
Aug 13 '05 #2
Thanks for the response. I too can get it to work if I use an old style
(ASP) form but it appears that the 2 objects I mentioned are not valid in an
ASP.NET environment?

Wayne

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:F5********************@comcast.com...
"Wayne Wengert" <wa***********@wengert.org> wrote in message
news:be********************@comcast.com...
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is

true?
I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET. How can I accomplish this?

Wayne

================= code ==============
<script language="Javascript">
<!--

var req;
var response;
var city;
var state;

function loadXMLDoc(url) {
// branch for native XMLHttpRequest object

if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state = response.getElementsByTagName('state')[0].firstChild.data;
alert(city);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" +
req.statusText);
}
}
}

function loadxml(form) {
loadXMLDoc('http://www.wengert.org/' +
'zipcodes.asmx/GetZip?z=' + document.forms[0].txtZIP.value);
}

//-->

</script>


I don't know about ASP.NET but this works for me:

<html>
<head>
<title>xml_zip.htm</title>
<script type="text/javascript">
var req;
var response;
var city;
var state;

function loadXMLDoc(url) {
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city =
response.getElementsByTagName('city')[0].firstChild.data;
state =
response.getElementsByTagName('state')[0].firstChild.data;
alert(city + ", " + state);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" + req.statusText);
}
}
}

function loadxml() {
loadXMLDoc('http://www.wengert.org/zipcodes.asmx/GetZip?z=' +
document.forms[0].txtZIP.value);
}
</script>
</head>
<body>
<form>
<input type="text" name="txtZIP" size="5" maxlength="5" value="">
<input type="button" value="Lookup" onclick="loadxml()">
<br>City, State :
<input type="text" name="txtcity">
<input type="text" name="txtstate">
<br>
<textarea name="output" cols="100" rows="30"></textarea>
</form>
</body>
</html>
I changed your
function loadxml(form) {
to
function loadxml() {
as well as the indentation for (my) readability.

Aug 13 '05 #3


Wayne Wengert wrote:
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is true?
I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET.
What you have below is client-side JavaScript code which is executed in
the browser and has no relevance to ASP.NET which is executed on the
server. Of course XMLHttpRequest respectively Microsoft.XMLHTTP are
used to load data from a HTTP server but whether that server runs
classic ASP or ASP.NET or JSP or PHP or no server side scripting
framework at all is not relevant to using XMLHttpRequest or
Microsoft.XMLHTTP on the client. So the statement "they do not appear to
be valid objects in ASP.NET" does not really make sense, the client has
to support the objects and XMLHttpRequest is supported by Mozilla,
Netscape 7/8, Opera 8, Safari 1.2, Konqueror 3.3, and Microsoft.XMLHTTP
by IE 5 and later on Windows.
<script language="Javascript"> if (window.XMLHttpRequest) { } else if (window.ActiveXObject) {
If something does not work as you want then it can have many reasons, if
you use Mozilla or Firefox check the JavaScript console first.
loadXMLDoc('http://www.wengert.org/'


You need to be aware that with normal security settings XMLHttpRequest
can load data only from the same HTTP server as the HTML document with
the script has been loaded from. So perhaps you are trying to access
that web service on www.wengert.org with a script in a HTML document
loaded from another server and then simply get no access.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 13 '05 #4
Marttin;

Thanks for the response. I think I need to do some studying to get an
understanding of all the items you mentioned.

Wayne

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:42***********************@newsread4.arcor-online.net...


Wayne Wengert wrote:
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is
true? I tried viewing those objects status but they do not appear to be
valid objects in ASP.NET.


What you have below is client-side JavaScript code which is executed in
the browser and has no relevance to ASP.NET which is executed on the
server. Of course XMLHttpRequest respectively Microsoft.XMLHTTP are used
to load data from a HTTP server but whether that server runs classic ASP
or ASP.NET or JSP or PHP or no server side scripting framework at all is
not relevant to using XMLHttpRequest or Microsoft.XMLHTTP on the client.
So the statement "they do not appear to be valid objects in ASP.NET" does
not really make sense, the client has to support the objects and
XMLHttpRequest is supported by Mozilla, Netscape 7/8, Opera 8, Safari 1.2,
Konqueror 3.3, and Microsoft.XMLHTTP by IE 5 and later on Windows.
<script language="Javascript">

if (window.XMLHttpRequest) {

} else if (window.ActiveXObject) {


If something does not work as you want then it can have many reasons, if
you use Mozilla or Firefox check the JavaScript console first.
loadXMLDoc('http://www.wengert.org/'


You need to be aware that with normal security settings XMLHttpRequest can
load data only from the same HTTP server as the HTML document with the
script has been loaded from. So perhaps you are trying to access that web
service on www.wengert.org with a script in a HTML document loaded from
another server and then simply get no access.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Aug 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sandro | last post by:
hello ng i know, probably i am not the first asking about this, but i am really dependent on it. i have an asp.net application (aspx/jscript with c# codebehind) and i am searching for a...
14
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values...
0
by: Joe | last post by:
Hi, I had a web service and all along able be invoked directly in IE within its asmx page. After someone upgrade the framework to 1.1 recently, all the invoke button gone. Anyway, the XML...
7
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i don´t want to filter the return value of the method, i have to pass a new instance of the...
1
by: A.M-SG | last post by:
Hi, I have a web service with two soap extensions enabled on it. When I run the default IIS method invoke page, the invoke button bypasses all my soap extensions. But when I call the...
1
by: PrettySneaky | last post by:
Hi, I'm currently developing my first .NET 2.0 webservice and I have stumbled into some problems. When i call webmethods from a console app which has a webreference to the webservice everything...
0
by: Standist | last post by:
vs.net 2003 I create a webservice using vc.net.In the webservice invoked a method in a dll from third party. I compile and link the program without any error.But I got a error when I debug it,I...
0
by: hammerjack | last post by:
401 Access Denied: Athentication Polices; <authentication> <identity impersonate="true" /> authentication/> <authorization> <allow users="*" /> <!-- Allow all users --> <authorization.>
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
5
by: Bilwin | last post by:
Hi , Is it possible to call a webservice method through AJAX.? If possible how can i do this? Thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.