Web Services, Part III: WebService's Methods: The callService() Method - Doc JavaScript | WebReference

Web Services, Part III: WebService's Methods: The callService() Method - Doc JavaScript


Web Services, Part III: WebService's Methods

The callService() Method

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:

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


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