Web Services, Part IV: WebService Behavior's Objects, Properties, and Events: The onserviceavailable Event Handler - Doc JavaScript | WebReference

Web Services, Part IV: WebService Behavior's Objects, Properties, and Events: The onserviceavailable Event Handler - Doc JavaScript


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

The onserviceavailable Event Handler

Most of the WebService behavior's properties belong to the three objects: call, result, and useOptions. The ones left out are serviceAvailable, serviceURL, and WSDL. They are all properties of the onserviceavailable event.

The serviceAvailable property is a Boolean indicating whether the WebService behavior obtained WSDL from the called Web service. A true value means the WebService behavior got WSDL. A false value means an error occurred and the WebService behavior did not get WSDL. In this case, a specific error code will be generated. Use this property to verify that a Web service is available and ready for remote calls.

An unsuccessful attempt to retrieve the WSDL from a Web service can occur for several reasons, mostly related to the network connection or the Web service itself. An easy way to debug this problem is to call the WSDL manually, by typing its URL in the browser address box.

If the serviceAvailable property is false, then the WSDL property of the same onserviceavailable event object is null because there was no WSDL coming back to the WebService behavior.

The serviceURL property is a string specifying the URL of the Web service that was called with the useService() method.

The userName property holds the user name of the account attempting to access a Web service. The WSDL property is the WSDL returned by the Web service.

The following example demonstrates the use of the onserviceavailable event. It uses this event to turn on the synchronous call button, only after it checked that the Web service is available and ready:

<HTML>
<BODY ID="webServiceCallerBody" onload="loadService()"
  STYLE="behavior:url(webservice.htc);
   background-color:peachpuff;color:brown;font-size:18">
<SCRIPT LANGUAGE="JavaScript">
<!--
function loadService() {
  webServiceCallerBody.onserviceavailable =
   enableServiceCall;  //Used for the synchronous call.
  webServiceCallerBody.useService(
    "https://soap.bluestone.com:80/interop/EchoService/
       EchoService.wsdl","echo");
}
function callAsynch() {
  iCallID = webServiceCallerBody.echo.callService
    (handleResult, "echoString", "Asynchronous Call");
}
function callSynch() {
  var co = webServiceCallerBody.createCallOptions();
  co.funcName = "echoString";
  co.async = false;
  var oResult = webServiceCallerBody.echo.callService
    (co, "Synchronous Call");
  handleResult(oResult);
}
function enableServiceCall() {
  b2.disabled = false;
}
function handleResult(res) {
  if (!res.error) {
    alert("Successful call. Result is " + res.value);
  }
  else {
    alert("Unsuccessful call. Error is "
      + res.errorDetail.string);
  }
}
// -->
</SCRIPT>
<HR><H4>Calls to an echo service</H4><HR><BR><BR>
<BUTTON ID="b1" onclick="callAsynch()">Call
  Asynchronously</BUTTON><BR><BR>
<BUTTON ID="b2" onclick="callSynch()" disabled>
  Call Synchronously</BUTTON><BR><BR><BR><BR>
<A HREF="https://www.xmethods.net/ilab/">
  Interop Testing Site</A>
</BODY>
</HTML>

Next: How to use the onresult event handler

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