Main Page

WebService component example

var oResult = window.event.result;
if ( == iCallID) {
if (oResult.error) {
alert(“An error occurred: “ + oResult.errorDetail.string);
} else {
alert(“Received back: “ + oResult.value);
iCallID = oService.FriendlyName.callService(...);
In this code, the
event handler first checks whether the result it’s handling is the response for
the appropriate request (in this way, a single
object can handle multiple requests). If the ID
of the result matches the call ID, the result is processed. The function ensures that there are no errors; if
an error occurs, the detailed error message is returned; otherwise the returned value is displayed.
Of course, it is up to you if you want to use the
property directly or use the
property to parse
the returned SOAP code on your own.
WebService component example
This example uses the Temperature Service described in the sample WSDL earlier in the chapter. Because
the Microsoft
component requires you to know only the WSDL location and the name of the
operation you want to call, you don’t need the WSDL to get this working.
The Web page for this example consists of a text box (with the ID
) and a button (labeled
). The user enters a zip code into the text box and then clicks the button to get the temper-
ature in that zip code (he calls the Web service). Of course, you also need an element to which you can
assign the
component. Here is the HTML:
<title>IE Web Service Example</title>
<script type=”text/javascript”>
<p><input type=”text” id=”txtZip” size=”10” /><input type=”button”
value=”Get Temperature” onclick=”callWebService()” />
<div id=”service” style=”behavior:url(”
The JavaScript to run this page is fairly simple:
var iCallID = null;
var sWSDL = “”;
Web Services
20_579088 ch17.qxd 3/28/05 11:42 AM Page 515

JavaScript EditorFree JavaScript Editor     Ajax Editor