|
|
 |
The onresult event fires when a result has been received from a remote Web service using the WebService behavior. It is only available to objects in the document to which the WebService behavior is attached. Here is an example that shows how to specify this event handler:
<DIV ID="service" STYLE="behavior:url(webservice.htc)"
onresult="onWSresult()">
You cannot specify both an onservice event handler and a function callback for the callService() method. If you do specify them both, the onresult event will not fire.
All properties of the event object are generally available in the Result object. They are:
- result.id. Returns a unique identifier that is associated with a particular instance of the
callService() method call.
result.value. Returns the value, or values, of the method call. The data type returned depends on the the definition of the method in the service description.
result.raw. Returns the whole XML data received from the server, including the packet headers and envelopes when SOAP is used.
result.error. Returns a Boolean, specifying if there has been an error. If true, the method call resulted in an error; if false, the method was called successfully.
When result.error is true (an error occurred), the errorDetail object is available as a property of the result object:
result.errorDetail.code. A cryptic error code. Can be VersionMismatch, MustUnderstand, Client, or Server.
result.errorDetail.string. A more descriptive error message. For example: "Error is Invalid argument."
result.errorDetail.raw. The entire XML data packet, received from the server.
The following example shows how to use the onresult event handler:
<SCRIPT LANGUAGE="JavaScript">
var iCallID;
function init() {
service.useService("/services/math.asmx?
WSDL","MyMath");
iCallID = service.MyMath.callService
("add",5,6);
}
function onWSresult() {
if((event.result.error)&&(iCallID==event.result.id)) {
var xfaultcode = event.result.errorDetail.code;
var xfaultstring = event.result.errorDetail.string;
var xfaultsoap = event.result.errorDetail.raw;
document.writeln("ERROR. Method call failed!");
document.writeln("Call ID:" + iCallID);
document.writeln("Fault Code:" + xfaultcode);
document.writeln("Fault String:" + xfaultstring);
document.writeln("SOAP Data:" + xfaultsoap);
} else if(event.result.error == false) {
document.writeln("Result received
without errors!");
}
}
</SCRIPT>
<BODY onload="init()">
<DIV ID="service" style="behavior:url(webservice.htc)"
onresult="onWSresult()">
</DIV>
</BODY>
|