Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Handling errors when calling a webservice

    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

    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);
    }
    I've tried this with "SmartClient Version 7.0beta4 (2009-02-19)" and Firefox 3.0.6 on Windows XP.
    Last edited by HHON; 21 Feb 2009, 09:11.

    #2
    Could someone from SmartClient please comment on this?

    Comment


      #3
      I am also at a loss on how exception handeling should be done with webservices. HHON presents a good set of cases that are most often encountered in an Enterprise environment.

      Isomorphic, any suggestion on how to handle this like methods to take over or secret methods we don't know about?

      Comment


        #4
        Hi guys,

        The behavior for (a) is correct. When a service returns an intact XML message you are intended to look at the fault code.

        (b) appears to be a regression. It looks like it would only happen if using the HttpProxy, can you confirm?

        (c) is also correct and is the same behavior you *should* get for (b). If there is a low-level error (transport error like 404, or timeout), instead of calling the normal callback, the system-wide RPCManager.handleError() is called. You can, alternatively, set willHandleError:true, which will cause your normal callback to be called with the bad response, however if you are on that beta4 nightly build, you're going to encounter the regression mentioned in (b).

        Comment


          #5
          Hi Isomorphic,

          thanks for your response.

          I've updated to build "Version 7.0beta4 (2009-03-05)". I've also elminated the use of HttpProxy, and added "willHandleError = true".

          Code:
          isc.RPCManager.defaultTimeout = 10000;
          isc.RPCManager.useHttpProxy = true;
          isc.RPCManager.willHandleError = true;
          
          var mySvc;
          var l = isc.HLayout.create();
          l.addMember(isc.IButton.create({title:"Call webservice", click:"callWS()"}));
          isc.XMLTools.loadWSDL("/DeployGui.asmx?WSDL", wsdlCallback);
          
          function callbackWs(data, xmlDoc, rpcResponse, wsRequest) {
            isc.clearPrompt();
            if (rpcResponse.httpResponseCode == 200) {
              isc.say("Call succeeded");
            } else {
              isc.say("Call failed");
            }
          }
          
          function wsdlCallback(svc) {
            isc.say("Got webservice");
            mySvc = svc;
          }
          
          function callWS() {
            isc.showPrompt("Calling webservice");
            mySvc.callOperation("WebMethod", "test", null, callbackWs);
          }
          I'm okay regarding (a) (webservice return HTTP error code) now - I've figured out how I can query the HTTP response code in the webservice callback function and detect an error when that code is != 200.

          However, regarding (b) (webservice not available), I still get the same "xmlDoc is null" exception, even when not using HttpProxy.

          Regarding (c) (webservice takes very long to respond), the callback function is still not executed if the webservice response takes longer than RPCManager.defaultTimeout. For example, when I set RPCManager.defaultTimeout to 10000 and my webservice waits 11 seconds before it answers, the callback is never executed. When the webservice waits only 9 seconds, the callback _is_ executed.
          Neither setting RPCManager.willHandleError to true or to false changes that behaviour. I've also set a Firebug breakpoint on RPCManager.handleError(), and that breakpoint is also never reached. And I don't see any JS errors (like "xmlDoc is null") in the JavaScript console either

          Comment


            #6
            I'm using 6.5.1 can't take hit to go to beta:

            a) Handling Error from server

            Yep that's working fine with willHandleError

            b) Connecting to an unavailable Server

            This fails whether with willHandleError or not. With willHandleError false and handleError method in the RPC Class, method below is not complete but it never gets called:

            Code:
                isc.RPCManager.addClassProperties ({
                    showPrompt: true,
                    promptStyle: "cursor",
                    defaultTimeout: 10000,
                    handleError : function (response, request) 
                        { 
                        if ( request.svcErrorHandler != undefined )
                            {
                            isc.Class.fireCallback(request.svcErrorHandler, "code,msg", [data.faultcode, data.faultstring]);
                            }
                        }
                     });
            I get the following from fireBug:

            Code:
            _1 is null
            38w()(null, "", Object operationId=custom clientContext=Object, Object actionURL=/appserver/services/WebClientService.v1)ISC_Data...=6.5.1.js (line 596)
            fireCallback()(Object target=[WebService ns=ns:webclient.opiniator.com], "xmlDoc,xmlText,rpcResponse,rpcRequest", [null, "", Object operationId=custom clientContext=Object, 1 more... 2=Object 3=Object Class=Array], [WebService ns=ns:webclient.opiniator.com] ns=Object, undefined)ISC_Core...=6.5.1.js (line 242)
            37c()(Object operationId=custom clientContext=Object, [Object 0=Object Class=Array], Object actionURL=/appserver/services/WebClientService.v1)ISC_Data...=6.5.1.js (line 56)
            fireCallback()(Object target=[Class XMLTools] methodName=$37c, "rpcResponse,data,rpcRequest", [Object operationId=custom clientContext=Object, [Object 0=Object Class=Array], Object actionURL=/appserver/services/WebClientService.v1 0=Object 1=[1] 2=Object Class=Array], [Class XMLTools] Class=XMLTools $bp=true $a5=false $b8=[Class Class], undefined)ISC_Core...=6.5.1.js (line 242)
            delayCall()(Object target=[Class XMLTools] methodName=$37c, "rpcResponse,data,rpcRequest", [Object operationId=custom clientContext=Object, [Object 0=Object Class=Array], Object actionURL=/appserver/services/WebClientService.v1 0=Object 1=[1] 2=Object Class=Array], undefined)ISC_Core...=6.5.1.js (line 334)
            evalResult()(Object target=[Class XMLTools] methodName=$37c, Object actionURL=/appserver/services/WebClientService.v1, Object operationId=custom clientContext=Object, [Object 0=Object Class=Array])ISC_Data...=6.5.1.js (line 734)
            a0()(Object actionURL=/appserver/services/WebClientService.v1, Object operationId=custom clientContext=Object)ISC_Data...=6.5.1.js (line 736)
            performOperationReply()(Object actionURL=/appserver/services/WebClientService.v1, Object operationId=custom clientContext=Object)
            ...
            c) Timeout

            Don't get a callback. None of the potential callbacks (handleError or Reply Handler) are called regardless of willHandleError being set. Interesing note. If you bring up the Console, you'll get an error in firebug on timeout but that's the only time I've seen it.

            Any possible work arounds will be acceptable!

            thanks in advance
            Last edited by ktyra; 13 Mar 2009, 04:24.

            Comment


              #7
              Anybody have any thoughts on the timeout or connection problem? I willing to do just about anything at this point

              Comment


                #8
                Hi ktyra,

                We've looked into this and discovered a bug when specifying willHandleError: true - this has now been fixed. The alternative option of using RPCManager.handleError works fine for us with the 7.0 codebase. Can you try it with 7.0 and let us know if you still see the problem? SmartClient releases have an enviable track record for being backward-compatible, so no need to think there'll be a big hit involved in moving to the latest release.

                Comment


                  #9
                  Thanks! Its good to know I haven't gone crazy. I will check out the 7.0 build and verify results.

                  Comment


                    #10
                    Using 7.0 Beta

                    With willHandleError:false && server web service stopped:


                    Code:
                    isc.RPCManager.addClassProperties({
                        showPrompt: true,
                        promptStyle: "dialog",
                        defaultTimeout: 10000,
                          });
                    Mozilia Reports:

                    Code:
                    _1 is null
                    http://localhost:8087/webclient/isomorphic/system/modules/ISC_DataBinding.js?isc_version=7.0beta.js
                    Line 706
                    
                    Stack:
                    38w()(null, "", Object operationId=custom clientContext=Object, Object actionURL=/appserver/services/WebClientService.v1)ISC_Data....0beta.js (line 706)
                    fireCallback()(Object target=[WebService ns=ns:webclient.opiniator.com], "xmlDoc,xmlText,rpcResponse,rpcRequest", [null, "", Object operationId=custom clientContext=Object, 1 more... 2=Object 3=Object Class=Array], [WebService ns=ns:webclient.opiniator.com] ns=Object, undefined)ISC_Core....0beta.js (line 255)
                    37c()(Object operationId=custom clientContext=Object, [Object 0=Object Class=Array], Object actionURL=/appserver/services/WebClientService.v1)ISC_Data....0beta.js (line 57)
                    fireCallback()(Object target=[Class XMLTools] methodName=$37c, "rpcResponse,data,rpcRequest", [Object operationId=custom
                    With the following set and the server in a paused state to cause a timeout:

                    Code:
                    isc.RPCManager.addClassProperties({
                        showPrompt: true,
                        promptStyle: "dialog",
                        defaultTimeout: 10000,
                        handleError : function (response, request) 
                            { 
                            alert("Timeout");
                            }
                         });
                    No event alert appears. We stay in a perpetual state of a dialog saying "Contacting Server". I let the server stay suspended for 5 minutes and then release it. Mozilla noted the return but the client was still hung in the "Contacting Server" state and the Console shows no RPC Requests.

                    I'm sure I'm doing something dumb but for the life of me I cannot figure out what.

                    Comment


                      #11
                      I can't get it to work either. Tried with Version 7beta4 (2009-03-16) and FireFox 3.0.7. Neither setting RPCManager.willHandleError = true/false or implementing RPCManager.handleError changes anything...

                      Isomorphic, have you actually tested it with the code I've posted earlier? Or could you please provide an example that works for you and that demonstrates how to handle the following error scenarions:

                      a) The webservice's webserver is stopped at the time of the webserivce call
                      b) The webservice takes too long to respond (longer than RPCManager.defaultTimeout)?

                      That would be really helpful. Thanks.

                      Comment


                        #12
                        I've just run my test case with SmartClient "Version 7.0beta9 (2009-04-18)":

                        Testcase "The webservice's webserver is stopped at the time of the webservice call" works now as expected. Very good!

                        However, the other testcase "The webservice takes too long to respond (longer than RPCManager.defaultTimeout)" still fails to execute the callback function, neither setting isc.RPCManager.willHandleError to true or to false has an impact.

                        Isomorphic, can you please comment on that behaviour? Can you reproduce that particular bug? Or can you provide some sample code that correctly handles such a timeout scenario?

                        Thanks.

                        Comment


                          #13
                          We're looking into it

                          Comment

                          Working...
                          X