2 Replies Latest reply on Dec 1, 2007 9:10 AM by lagunajc

    Can you get the requested operation from SOAP ResultEvent?

    lagunajc
      First of all, sorry if this is posted in the wrong place, I wasn't quite sure where else to ask really.

      Basically I have a WebService object, which I call several different operations on, but each one is handled by the same function, onResult(event:ResultEvent)

      Is there a nice/recommended way of getting the operation that was requested from this event? So for example I could do switch(event.operation)

      Currently I'm doing this by e.token.message.getSOAPAction() and working it out the operation from there, but this seems quite a hacky solution, which is why I was wondering if there was a recommended way of doing it?

      Thanks
      Jason
        • 1. Re: Can you get the requested operation from SOAPResultEvent?
          Level 7

          You can move the result handler from the web service to each operation and
          create different handlers:

          <mx:WebService id="ws" wsdl="..." >
          <mx:operation name="getSomething" result="getSomethingResult(event)" ...
          <mx:operation name="getOther" result="getOtherResult(event)" ...
          <mx:operation name="getDifferent" result="getDifferentResult(event)" ...
          </mx:WebService>


          Or, you can make use of the Asynchronous Completion Token (ACT) pattern and
          decorate the AsyncToken that is returned when you invoke the operation:

          import mx.rpc.AsyncToken;

          ...

          var token:AsyncToken = ws.getSomething();
          token.myOperation = "getSomething";

          ...

          private function getSomethingResult(event:ResultEvent):void
          {
          if (event.token.myOperation == "getSomething")
          {

          }
          else
          ...
          }

          Or, if you need invocation level responders, even for the same operation,
          you can add a responder to the token itself...

          import mx.rpc.AsyncToken;
          import mx.rpc.IResponder;
          import mx.rpc.Responder;
          ...

          var token:AsyncToken = ws.getSomething();
          var responder:IResponder = new Responder(handleSpecialResult, handleSpecialFault);
          token.addResponder();


          private function handleSpecialFault(event:FaultEvent):void
          {
          ...
          }

          private function handleSpecialResult(event:ResultEvent):void
          {
          // You can also prevent the default operation-level or service-level
          handlers from receiving this event
          event.preventDefault();
          ...
          }


          Hello lagunajc,

          > First of all, sorry if this is posted in the wrong place, I wasn't
          > quite sure where else to ask really.
          >
          > Basically I have a WebService object, which I call several different
          > operations on, but each one is handled by the same function,
          > onResult(event:ResultEvent)
          >
          > Is there a nice/recommended way of getting the operation that was
          > requested from this event? So for example I could do
          > switch(event.operation)
          >
          > Currently I'm doing this by e.token.message.getSOAPAction() and
          > working it out the operation from there, but this seems quite a hacky
          > solution, which is why I was wondering if there was a recommended way
          > of doing it?
          >
          > Thanks
          > Jason


          • 2. Re: Can you get the requested operation from SOAPResultEvent?
            lagunajc Level 1
            Thanks for the detailed reply
            I changed my code to use the first solution in the end, whereby each operation is handled by a separate function, it was the easiest way to do it because I didn't want to add any extra code to where the web service was being called from (since the code for handling the results was in a separate class to where the operations were being called)