spacer

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

home / experts / javascript / column98


Web Services, Part III: WebService's Methods

The callService() Method

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

The callService() method initiates the engagement of the WebService behavior with the Web service. Here is the syntax:

iCallID = sElementID.sFriendlyName.callService(
  [oCallHandler], funcOrObj, oParam);

where:
  • iCallID is the returned ID of the service call. In case of asynchronous call, this ID should be matched with the ID returned as a property of the result object. Only when matched can the result object be associated with this service call.
  • sFriendlyName is the friendly name associated with the Web service. Call the useService() method to assign a friendly name to your Web service. See Page 6 for details.
  • oCallHandler is the callback handler function for processing the result object. This parameter is optional.
  • funcOrObj is either the Web service's method you want to call, or the call options object. You can set this object with the createCallOptions() method (see Page 5 for details). You don't have to set all nine properties, but be sure to set its funcName property to the Web service's method you want to call. If not set, WebService won't know which Web service's method to call. This parameter is required.
  • oParam are a comma-delimited list of parameters that the Web service's method expects. This parameter is required.

The following example shows a call to callService() without the first, optional parameter:


oResult = webServiceCallerBody.echo.callService(co,
  "Synchronous Call");

The name of the service's method is set in the call options object as follows:

var co = webServiceCallerBody.createCallOptions();
co.funcName = "echoString";

The parameter list sent to the Web service includes only one string parameter, "Synchronous Call".

Here is another example:

iCallID = service.MyMath.callService("add", 5, 6);

The name of the method ("add") is passed here explicitly, and not as a property of the call options object, as in the first example above. Two parameters are passed to the add method, 5 and 6.

The following example demonstrates the usage of a callback handler function, handleResult:


iCallID = webServiceCallerBody.echo.callService
  (handleResult, "echoString", "Asynchronous Call");

where handleResult() is defined as follows:

function handleResult(res) {
  if (!res.error) {
    alert("Successful call. Result is " + res.value);
  }
  else {
    alert("Unsuccessful call. Error is "
      + res.errorDetail.string);
  }
}

Notice that the result object res is passed as a parameter to the callback handler function.

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 3, 2001
Revised: December 3, 2001

URL: http://www.webreference.com/js/column98/7.html