I need to call a webservice from my app using WebService.callOperation, and I'd like to add some error handling in case the webservice
a) returns an error (I simulated that by throwing an exception inside the web service code)
b) is not available (I simulated that by stopping the smartclient server - which I use as proxy - prior to calling the webservice)
c) takes too long (I simulated that by waiting for a couple of minutes inside the web method before returning)
There are also two different call scenarios:
1) Doing callOperation with resultType set to null
2) Doing callOperation with resultType set to some XPath expression
How can I handle all of those possible error cases?
As of now, I can only handle a1) by looking for data.faultcode in the callback.
For a2), I simly get an empty array, which may as well be a valid response.
For b), I get the exception "xmlDoc is null, WebService.js line 431, xmlDoc.addNamespaces(this.getOutputNamespaces..."
For c), the callback function gets never executed.
Here's my test code
I've tried this with "SmartClient Version 7.0beta4 (2009-02-19)" and Firefox 3.0.6 on Windows XP.
a) returns an error (I simulated that by throwing an exception inside the web service code)
b) is not available (I simulated that by stopping the smartclient server - which I use as proxy - prior to calling the webservice)
c) takes too long (I simulated that by waiting for a couple of minutes inside the web method before returning)
There are also two different call scenarios:
1) Doing callOperation with resultType set to null
2) Doing callOperation with resultType set to some XPath expression
How can I handle all of those possible error cases?
As of now, I can only handle a1) by looking for data.faultcode in the callback.
For a2), I simly get an empty array, which may as well be a valid response.
For b), I get the exception "xmlDoc is null, WebService.js line 431, xmlDoc.addNamespaces(this.getOutputNamespaces..."
For c), the callback function gets never executed.
Here's my test code
Code:
var mySvc; var l = isc.HLayout.create(); l.addMember(isc.IButton.create({title:"Call with null", click:"callWithNull()"})); l.addMember(isc.IButton.create({title:"Call with XPath", click:"callWithXPath()"})); isc.XMLTools.loadWSDL("http://localhost:1352/MyWebService.asmx?WSDL", wsdlCallback); function callbackXPath(data) { isc.clearPrompt(); // Howto determine whether call was successful? } function callbackNull(data) { isc.clearPrompt(); if (data.faultcode) { isc.say("Call failed"); } } function wsdlCallback(svc) { isc.say("Got webservice"); mySvc = svc; } function callWithNull() { isc.showPrompt("Calling webservice with null"); mySvc.callOperation("WebMethod", "test", null, callbackNull); } function callWithXPath() { isc.showPrompt("Calling webservice with XPath"); mySvc.callOperation("WebMethod", "test", "/service:test", callbackXPath); }
Comment