November 18, 2001 - Checking the result Object | WebReference

November 18, 2001 - Checking the result Object

Yehuda Shiran November 18, 2001
Checking the result Object
Tips: November 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

When you call a Web service, you actually send a message to the service and then receive another message as a response. You send a message via the callService() method. Here is an example for calling a Web service in Internet Explorer:

iCallID = webServiceCallerBody.echo.callService(handleResult, "echoString", 
  "Asynchronous Call");
The response message, or errors encountered during the interaction with the Web service, are attached to an object, called the result object. If you want to find the result of your query to the Web service, you need to analyze the result object. First, you need to know where you can get it for analysis. Well, it depends on how you call the Web service. If you specify an event handler in the callService() method (first parameter), the result object will be passed as a parameter to this event handler. Here is the handleResult() function from the above callService() example:

function handleResult(res) {
  if (!res.error) {
    alert("Successful call. Result is " + res.value);
  }
  else {
    alert("Unsuccessful call. Error is " + res.errorDetail.string);
  }
}
If you don't specify an event handler in the callService() method, you can get the result object as a property of the event object. You first specify the onresult event handler like here:

<BODY ID="webServiceCallerBody" onresult="onWSresult()" 
style="behavior:url(webservice.htc)">
And you define the onWSresult() as follows:

function onWSresult() {  
  if((event.result.error) ...
}