↑
Main Page
JavaScript execution
When this method is called, the component downloads the WSDL file and uses it to create JavaScript
objects and methods to access the Web service. This functionality is available through an object identi-
fied by the friendly name specified in the
useService()
method:
var oSpecificService = oService.FriendlyName;
This object has a method,
callService()
, that makes the actual request to the server. The method
accepts a function name to call and any number of parameters to pass to that function. When executed,
callService()
returns a call ID that is necessary when you want to retrieve a value from the result.
The format for this method call is as follows:
iCallID = oService.FriendlyName.callService(sFuncName, sParam0, sParam1..sParamN);
The Web service call is then made asynchronously, so JavaScript execution won’t stop and wait for the
response from the server. Instead, you must use the
onresult
event handler to handle the response. You
can either assign the event handler right in the HTML or by using JavaScript. Using HTML, just treat
onresult
as if it were any other event handler:
<div id=”service” style=”behavior(webservice.htc)” onresult=”alert(‘Done’) “></div>
To assign the event handler using JavaScript, assign the function directly to the
onresult
property:
oService.onresult = function () {
alert(“Done”);
};
When the
result
event is fired, it creates an
event
object with a special property called
result
. This
property contains an object with all the details about the response. The properties of
result
are listed in
the following table:
Property Name
Data Type
Description
error
Boolean
True if an error occurred during the call
errorDetail
Object
An object that contains all the information about an
error, if one occurs. The two properties of interest are
the code that returns the error code and the string that
returns a human-readable error message.
id
Number
The call ID created by
callService()
raw
String
The raw SOAP code being sent back from the server
SOAPHeader
Array
An array of headers used for the call
value
Variant
The value returned by the call. This may be a simple data
type, like a number or string, or it could be an object.
So how do you use this object? Here’s a simple example:
var iCallID = -1;
oService.onresult = function () {
514
Chapter 17
20_579088 ch17.qxd 3/28/05 11:42 AM Page 514
Free JavaScript Editor
Ajax Editor
©
→