spacer
Yehuda Shiran December 20, 2001
Giving Friendly Error Messages
Tips: December 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

When calling a remote Web service, errors can and will occur. The trick is how to debug the result's errorDetail object, to find as many clues as possible regarding the source of the problem. The string property is a human-readable fault code. If the code property gives a very brief machine-readable message, the string property gives a much more elaborate message that makes sense to the user. For example, try calling a Web service with a wrong function name. You will receive an errorDetail object where string is "Error is Invalid argument." Here is the html page with the error:

<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, "echoStringg", "Asynchronous Call");
}

function callSynch() {
	var co = webServiceCallerBody.createCallOptions();
	co.funcName = "echoStringg";
	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="http://www.xmethods.net/ilab/">Interop Testing Site</A>

</BODY>
</HTML>
Notice the error in the remote service function, "echoStringg" instead of "echoString". Download webservice.htc. You are ready to click one of the buttons and see the error message coming out of the WebService behavior.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint