spacer
Yehuda Shiran December 3, 2001
Calling the EchoInteger Web Service
Tips: December 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

When calling a Web service, you need to pay close attention to its expected input data type. When the input is of type integer, you may send an integer or a quoted integer. You send the input integer to the Web service by assigning the third parameter of the callService() method. The following call will be successful:

iCallID = webServiceCallerBody.echo.callService(handleResult, "echoInteger", 
  5);
As well as the following call:

iCallID = webServiceCallerBody.echo.callService(handleResult, "echoInteger", "5");
If you send a non-quoted string, the JavaScript interpreter will assume it is a variable and will complain that the variable is undefined. Therefore, the following line of code will yield an error:

iCallID = webServiceCallerBody.echo.callService(handleResult, "echoInteger", abc);
If you send a floating number, a quoted floating number, or a string, the response from the Web service will include an error. The following line of code:

iCallID = webServiceCallerBody.echo.callService(handleResult, "echoInteger", 5.6);
Will yield the following error:

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(
	  "http://soap.bluestone.com:80/interop/EchoService/EchoService.wsdl","echo");
}
function callAsynch() {
	iCallID = webServiceCallerBody.echo.callService(
	  handleResult, "echoInteger", 5);
}
function callSynch() {
	var co = webServiceCallerBody.createCallOptions();
	co.funcName = "echoInteger";
	co.async = false;
	var oResult = webServiceCallerBody.echo.callService(co, 5);
	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="http://www.xmethods.net/ilab/">Interop Testing Site</A>

</BODY>
</HTML>

People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Workers Say Telework Is More Productive, Bosses Not So Sure · Kingston Debuts Power-Saving Memory Upgrades · Social Networking is King: Facebook Edges Google