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:
where:iCallID = sElementID.sFriendlyName.callService( [oCallHandler], funcOrObj, oParam);
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 theresult
object. Only when matched can theresult
object be associated with this service call.sFriendlyName
is the friendly name associated with the Web service. Call theuseService()
method to assign a friendly name to your Web service. See Page 6 for details.oCallHandler
is the callback handler function for processing theresult
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 thecreateCallOptions()
method (see Page 5 for details). You don't have to set all nine properties, but be sure to set itsfuncName
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
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: December 3, 2001
Revised: December 3, 2001
URL: https://www.webreference.com/js/column98/7.html