December 8, 2001 - Calling the EchoDate Web Service | WebReference

December 8, 2001 - Calling the EchoDate Web Service

Yehuda Shiran December 8, 2001
Calling the EchoDate Web Service
Tips: December 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

When calling a Web service, you need to pay close attention to its expected input data type. When the input is of type date, the format is "yyyy-MM-ddTHH:mm:ss". For example, 2001-12-08T01:17:00 is the date 8th December 2001 and time 17 minutes past 1 O'clock. The following call:

iCallID = webServiceCallerBody.echo.callService(
  handleResult, "echoDate", 2001-12-08T01:17:00);
will convert this date to a UTC format. It will assume the date above is in the UTC+0 time zone, and will convert it to a local time. For a UTC+2 region, you'll get the following alert box:

Learn more about Web services in Column 96 (Web services, Part I: Introduction) and Column 97 (Web Services, Part II: Calling Service Methods).

Here is an HTML file that demonstrates calling a Web service. Copy it to your local disk, together with the WebService behavior (webservice.htc):

<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, "echoDate", 2001-12-08T01:17:00);
}
function callSynch() {
	var co = webServiceCallerBody.createCallOptions();
	co.funcName = "echoDate";
	co.async = false;
	var oResult = webServiceCallerBody.echo.callService(co, 2001-12-08T01:17:00);
	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>