<< DG2- GUI and Design Group

Blog

Our Blog

Blog Home | About | Entries By Date | Search

Posts

1-1 of 1

Flex 3, WebService, ASyncToken and IResponder
Entry posted on Dec 16 by Lenny Fontes

Title: Flex 3, WebService, ASyncToken and IResponder
Entry:

I’ve built many web service based applications in Flash AS 2.0; and it’s always been a nightmare to track the Asyncronous calls to a web service, pending result responses and faults. But I was recently introduces to Flex Builder 3, running the 3.2 framework, and I’m feeling MUCH better about web services. I’m having issue when attempting to use the Flexbuilder GUI under Data> Importing Web Services (WSDL). So I’ve had to create my own classes and methods to support my applications; Then I researched ASyncToken, and IResponder and I was exstatic. let me show you some code:

<mx:Script>
 <![CDATA[
  import mx.rpc.AsyncToken;
  import mx.rpc.Responder;
  import mx.rpc.events.FaultEvent;
  import mx.rpc.events.ResultEvent;
  import mx.rpc.soap.mxml.WebService;
  private var ws:WebService�
  private var token:AsyncToken
  private var responder:mx.rpc.Responder
  public function init():void{
   var ws:WebService = new WebService();
   ws.wsdl = "http://myservice.com/?wsdl"
   
  }
  public function callMyTestMethod(params:*):void
  {
   token:ASyncToken = ws.myTestMethod();
   responder = new Responder(catchResult, catchFault)
   token.faultMessage = "myTestMethod Failed"
   token.otherParams = "other parameters"
   token.addResponder(responder);
  }
  
  private function catchResult(e:ResultEvent):void{
   myResultObject = e.results
   //Do something with the results. And by the way,�
   //access your Token object in this method through
   //the ResultEvent.token object;
   token = e.token;   
  }
  
  private function catchFault(e:FaultEvent):void{
     //Don't forget the FaultEvent.token object...�
   token = e.token;
   mx.controls.Alert.show(e.fault.faultString, token.faultMessage)�
   //I've created a log method to track all errors as well.
   log(e.fault.getStackTrace());
  }
  ...

Using this AsyncToken, and Responder interface, I’ve been able to successfully re-use a single WebService component, and track responses and faults from those services without serious concern. Now that I can track objects and pass parameters in the token, I’ve been able to daisy-chain services that are co-dependant to update data in a database, without the fear of the Race Condition.  The best part about it; no more  generic addEventListeners to the WebService. I can have a different listener per method.  –Lenny

 

 


Filter by Date

<< May 2013 >>
Su Mo Tu We Th Fr Sa
      01 02 03 04
05 06 07 08 09 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Filter by Tag

All
Design
Development
Event
Interactive Experience
Mobile
News
Print
Rich Internet Apps
Video

Change View

Titles
Summaries
Table
Clip
Clip & Comments
Full

Change Sort

Alphabetically
By Last Activity
By Date Posted
By Number of Comments
By Number of Views
By Author