1 Reply Latest reply on Jul 21, 2008 2:13 PM by Kurt Mossman

    Webservice error messages

    stigbn Level 1
      Hi All
      I am using a web service to feed my flex application with data. When exceptions occur in the web service, I only get some generic error message in my fault handler. I would like to be able to get information such as error messages from the web service exceptions propagated to my web service fault handlers in my Flex Application.

      My web service is .Net based/C# and it is used in my Flex app by importing the WSDL file of the service.

      Here is an example with some code snippets:

      The web service has a HelloWorld webmethod which throws an exception. This webservice is imported into my flex app using the Data->Import Webservice feature, which autogenerates the webserivce class I am using. When I call the webservice from Flex, the fault handler is called but it only contains some generic error message.

      Code snippets: The C# webservice method which throws an exception:
      [WebMethod]
      public string HelloWorld()
      {
      throw new Exception("Hello World Exception.");
      return "Hello World";
      }

      And here is how I call the webservice in my FIex App:

      private function btnTestWebserviceClicked(event:Event):void
      {
      var service:WebService = new WebService();
      service.addWebServiceFaultEventListener(faultHandler);
      service.addhelloWorldEventListener(webMethodDone);
      service.helloWorld();
      function webMethodDone(event:HelloWorldResultEvent):void
      {
      Alert.show("Done", "Done");
      }
      function faultHandler(event:FaultEvent):void
      {
      Alert.show(event.fault.faultString, "Error");
      }
      }

      The information I can get from the faultEvent passed to the fault handler does not contain the error string but only the generic "HTTP request error" error message, and not the “Hello World Error String” which was passed to the exception thrown in the webservice.

      So my question is: How can I get information from web service exceptions propagated to my fault handlers in Flex?

      Any help, advice or pointers to articles will be much appreciated.
      Best regards Stig Nielsson
        • 1. Re: Webservice error messages
          Kurt Mossman Adobe Employee
          Hi Stig,

          The root cause of the problem is that the body of the 500 status code isn't returned to the flash player from the browsers. This prevents the Flash Player from passing it along to you. Keep in mind that the FlashPlayer is just a control that runs within the browser; as a result it's restricted by what the browser provides to it. The body of a 500 error message isn't one of the things provided to it.

          The Flash Player needs to play to the least common denominator and while some browsers do provide the web service's 500 error body the Flash Player requires ubiquity. This is why the feature isn't implemented within the Flash Player... when all browsers provide this data then Adobe needs to add the feature. Adobe has logged a bug on these issues with the browser companies.

          To workaround the issue use LCDS or BlazeDS as proxies. They have been coded to return a 200 status response instead of the 500 error allowing you to access the error message. Adobe has been aware of this issue and this is the suggested resolution to the problem. It's not ideal but it's the best we currently have available.

          Here's a great article that talks about this:
          http://blog.flexmonkeypatches.com/2008/05/16/soap-fault-messages-in-flexflash-player-error -2032-stream-error/

          -Kurt.