Web Services, Part IV: WebService Behavior's Objects, Properties, and Events: The Call Object (1) - Doc JavaScript | WebReference

Web Services, Part IV: WebService Behavior's Objects, Properties, and Events: The Call Object (1) - Doc JavaScript


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

The Call Object (1)

The call object is used to specify additional parameters that are sometimes required by Web Services. This object has nine properties.

The async property specifies the mode of remote method invocation. Set it to false for a synchronous call of the Web service, and to true for an asynchronous call. The default value is true, so you must set it to false if you want to call the Web service synchronously. The way you do it is by passing the call object as the first parameter of the callService() method, as shown here:


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

where co is the call object.

The endpoint property specifies an URL that can be used to obtain the Web Services Description Language (WSDL) for a Web Service. This property corresponds to the location attribute of the <soap:address> element in the Web Services Description Language (WSDL) file. Here is an example:

<SCRIPT LANGUAGE="JavaScript">
function callWebService() {
  webServiceID.useService(
    "https://soap.bluestone.com:80/interop/EchoService/
      EchoService.asmx","echo");
  var objCall = new Object();
  objCall.funcName = "echoString";
  objCall.endpoint = "/anotherURL/EchoService.wsdl";
  webServiceID.echo.callService (fnHandler, objCall, "abc");
}
function fnHandler(res) {
  if (!res.error) {
    alert(res.value);
  } else {
      alert(res.errorDetail.string);
    }
}
</SCRIPT>

The funcName property specifies a remote function exposed by a Web service function to call. EchoService, for example, exposes the functions echoString, echoInteger, echoArrayInteger, etc.

The params property specifies an associative array of parameter values that are passed as the arguments of a remote method invocation. This property provides an alternative to specifying a list of parameters in the callService method (default). The associative array can be used to pass complex data types to the Web service function. There may be several reasons to use these parameters. Sometimes, you need to iterate over several Web services, each one with slightly different parameters. You can prepare these parameter lists a priori. Another advantages is that you don't need to keep the order of the parameters as you do when passing them through the callService() method. An associative array enables the definition of the name-value pairs, which makes the definition of the parameters submitted to a Web method order-independent. Here is an example:

<SCRIPT LANGUAGE="JavaScript">
function init() {
  proxy.useService("employee.asmx", "EmployeeService");
  var objCall = new Object();
  objCall.funcName = "echoEmployee";
  objCall.params = new Array();
  objCall.params.name = "Fred";
  objCall.params.male = "true";
  objCall.params.age = "32";
  objCall.params.worth = "654000.00";
  objCall.params.hireDate = "01/10/2001";
  objCall.params.title = "Developer";
  proxy.EmployeeService.callService (fnHandler, objCall);
}
function fnHandler(res) {
  if (!res.error) {
    alert(res.value);
  } else {
      alert(res.errorDetail.string);
    }
}
</SCRIPT>
<BODY>
<DIV ID="proxy" STYLE="behavior:url('webservice.htc');">
</DIV>
</BODY>

Next: What are call object's properties (2)

https://www.internet.com


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

URL: https://www.webreference.com/js/column99/2.html