December 4, 2001 - Calling the EchoFloat Web Service | WebReference

December 4, 2001 - Calling the EchoFloat Web Service

Yehuda Shiran December 4, 2001
Calling the EchoFloat 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 float, you may send a decimal number, an integer, a floating number, a quoted decimal, a quoted integer, or a quoted floating number. You send the input decimal number to the Web service by assigning the third parameter of the callService() method. The following calls will be successful:

iCallID = webServiceCallerBody.echo.callService(handleResult, "echoFloat", 5.6e-3);
iCallID = webServiceCallerBody.echo.callService(handleResult, "echoFloat", 5.6);
iCallID = webServiceCallerBody.echo.callService(handleResult, "echoFloat", 5);
iCallID = webServiceCallerBody.echo.callService(handleResult, "echoFloat", "5.6e-3");
iCallID = webServiceCallerBody.echo.callService(handleResult, "echoFloat", "5.6");
iCallID = webServiceCallerBody.echo.callService(handleResult, "echoFloat", "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, "echoFloat", abc);
If you send a quoted string as follows:

iCallID = webServiceCallerBody.echo.callService(handleResult, "echoFloat", "a");
The Web service will return the following error message:

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 (

<BODY ID="webServiceCallerBody" onload="loadService()" 
function loadService() {
	webServiceCallerBody.onserviceavailable = enableServiceCall;  //Used for the synchronous call.
function callAsynch() {
	iCallID = webServiceCallerBody.echo.callService(
	  handleResult, "echoFloat", 5.6e-3);
function callSynch() {
	var co = webServiceCallerBody.createCallOptions();
	co.funcName = "echoFloat";
	co.async = false;
	var oResult = webServiceCallerBody.echo.callService(co, 5.6e-3);
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);
// -->
<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="">Interop Testing Site</A>