November 22, 2001 - Handling the result Object
November 22, 2001 Handling the result Object Tips: November 2001
Yehuda Shiran, Ph.D.
|
add
method with two arguments, intA
and intB
:
iCallID = service.MyMath.callService(mathResults,"add", intA, intB);
The event handler mathResults()
accepts the result object as its sole parameter:
function mathResults(result)
The name of the parameter can be different than "result"
. Inside, it checks whether there were errors during the call to the Web service:
if (result.error) { .... }
Use this check to write an event handler that processes the result
object and prints the error details (if any) as well as the result value. Here is a Microsoft example:
<SCRIPT language="JavaScript">
<!--
// All these variables must be global,
// because they are used in both init() and onResult().
var iCallID = 0;
var intA = 5;
var intB = 6;
function init() {
service.useService("/services/math.asmx?WSDL","MyMath");
iCallID = service.MyMath.callService(mathResults, "add", intA, intB);
}
function mathResults(result) {
if(result.error) {
var xfaultcode = result.errorDetail.code;
var xfaultstring = result.errorDetail.string;
var xfaultsoap = result.errorDetail.raw;
} else{
alert(intA + ' + ' + intB + " = " + result.value);
}
}
// -->
</SCRIPT>
<BODY onload="init()">
<DIV ID="service" style="behavior:url(webservice.htc)">
</DIV>
</HTML>