spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column99


Web Services, Part IV: WebService Behavior's Objects, Properties, and Events

Using the result Object

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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>

Next: How to use the onserviceavailable event handler

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: December 17, 2001
Revised: December 17, 2001

URL: http://www.webreference.com/js/column99/5.html