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

The onresult Event Handler

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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>

Next: A Final Word

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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/7.html