Main Page

SOAP error

Once again, the first function is named
. The first step must be a request for
enhanced privileges as described previously. If the privileges aren’t given, there’s no point in the func-
tion continuing, so it returns. If the privileges are enabled, then the zip code is retrieved and placed in a
array. Lastly, the SOAP call is created and made asynchronously:
function callWebService() {
try {“UniversalBrowserRead”);
} catch (e) {
return false;
var sZip = document.getElementById(“txtZip”).value;
var arrParams = new Array;
arrParams[0] = new SOAPParameter(sZip, “zipcode”);
var oSoapCall = new SOAPCall();
oSoapCall.transportURI = sURL;
oSoapCall.encode(0, “getTemp”, sTargetNamespace, 0, null,
arrParams.length, arrParams);
Next, the
function handles the response. Most of the function is dedicated to
determining if an error occurred during the Web service call:
function onWebServiceResult(oResponse,oSoapCall,iError) {
if (iError != 0) {
alert(“An unspecified error occurred.”);
} else if (oResponse.fault != null) {
alert(“An error occurred (code=” + oResponse.fault.faultCode
+ “, string=” + oResponse.fault.faultString + “)”);
} else {
var oParams = oResponse.getParameters(false, {});
alert(“It is currently “ + oParams[0].element.firstChild.nodeValue
+ “ degrees in that zip code.”);
The first step in this function is to check the error code
. If it’s not equal to
, that means there
isn’t a response to evaluate, so an error message is displayed. If the error code is
, the next step is to
determine that there wasn’t a SOAP error. This ensures that the
property is
(if it’s not, a
detailed error message is displayed).
When the two other conditions fail, the response must be valid. So, the value of the first parameter is
displayed in a user-friendly message.
Web Services
20_579088 ch17.qxd 3/28/05 11:42 AM Page 521

JavaScript EditorFree JavaScript Editor     Ajax Editor