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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business