|
|
 |
The result object can be handled in two ways. If you specify a callback function in callService(), result is passed as the first parameter to this callback function. Here is an example:
<SCRIPT LANGUAGE="JavaScript">
var iCallID;
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>
</BODY>
If a callback function is not used, the event object of the onresult event exposes the result object. Here is an 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("add", intA, intB);
}
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;
} else if((!event.result.error) && (iCallID ==
event.result.id)) {
alert(intA + ' + ' + intB + ' = '
+ event.result.value);
} else {
alert("Something else fired the event!");
}
}
// -->
</SCRIPT>
<BODY onload="init()">
<DIV id="service" STYLE="behavior:url(webservice.htc)"
onresult="onWSresult()">
</DIV>
</BODY>
|