Hey Phil,

Sure, let's go over ASyncToken and IResponder.

ASyncToken
(http://livedocs.macromedia.com/flex/2/langref/mx/rpc/AsyncToken.html)
>From the docs: This class provides a place to set additional or
token-level data for asynchronous rpc operations. It also allows an
IResponder to be attached for an individual call. The AsyncToken can
be referenced in ResultEvent and FaultEvent from the token property.

So we capture the token/id of the remote call we're making by
assigning it to an ASyncToken instance, and then we can attach classes
that implement the IResponder interface as responders.

var call:ASyncToken = op.send();
call.addResponder(myResponderClass);

myResponderClass must be an instance of a class that implements the
IResponder interface
(http://livedocs.macromedia.com/flex/2/langref/mx/rpc/IResponder.html).
IResponder dictates that your class contains a result() method and a
fault() method. These methods (at least the appropriate one depending
on the success of your request) will be automatically called by the
ASyncToken when the remote call returns. The parameter for both
methods is of type object, but what is returned from a web service
call is either ResultEvent or FaultEvent, so you'll generally cast it
inside the method.

This approach allows you to have more than one object that will be
called when your service returns if you so choose.

HTH,
Ben


--- In [email protected], "phipzkillah" <[EMAIL PROTECTED]> wrote:
>
> Ben,
> 
> What is the best way to go about handling the result from the
> operations.send() call.  I'm sure you must have to add an event
> listener on the operations call.  
> 
> I do not fully understand the Iresponder from your initial posting.
> 
> <<
> You can optionally capture the token created by the call and assign a
> responder as well:
> 
> var call:ASyncToken = op.send();
> call.addResponder(IResponder);
> The IResponder interface defines a result and fault method that are
> called when the operation returns. >>
> 
> I tried to add that into my code and received the error:
> 
> 1046: Type was not found or was not a compile-time constant: ASyncToken.
> 
> I believe I have all the proper classes imported:
> 
> import mx.rpc.soap.WebService;
> import mx.rpc.soap.WSDL;
> import mx.rpc.soap.*;
> import mx.rpc.IResponder;
> import mx.rpc.*;
> import mx.rpc.events.ResultEvent;
> import mx.rpc.AsyncToken;
> 
> Now even if I get the error eliminated, how do you add a resultHandler
> function to capture the xml returned from the operations call?
> 
> Maybe you can briefly explain how the AsyncToken and Iresponder work?
> 
> Here is my current snippet of code:
> private function init():void{
>                       var ws:WebService = new WebService;
>                       ws.wsdl = 
> "http://www.myservice.com/services/InventoryService?wsdl";;
>                       ws.useProxy = false;
>               
ws.loadWSDL("http://www.myservice.com/services/InventoryService?wsdl";);
>                       
>                       var op:Operation = ws.getOperation("getPhones") as 
> Operation;
>                       op.arguments.projectId = 1;
>                       op.resultFormat= "e4x"; 
>                       
>                       //var call:ASyncToken = op.send(); //1046 error
>                       //call.addResponder(IResponder);                
>                                               
>                       op.send();
>               }
> 
> Thanks for all your help to far.  It has definitely helped!!
> 
> --Phil
> 
> --- In [email protected], "ben.clinkinbeard"
> <ben.clinkinbeard@> wrote:
> >
> > > is that the method we are trying to call through the web service?
> > Yep.
> > 
> > You know, I almost included the bit about e4x the first time but
> > decided against it. For that you simply do op.resultFormat = "e4x";
> > 
> > Flex handles the serialization of your objects for you, so you just
> > put the arguments your method requires onto the arguments property. So
> > if your remote method's signature is: doCoolStuff(name:String,
> > age:Number, hobbies:Array), you would use the following code in Flex:
> > 
> > op.arguments.name = "Bob Cratchett";
> > op.arguments.age = 34;
> > op.arguments.hobbies = new Array("working", "playing with Tim",
"etc");
> > 
> > HTH, let me know if you have additional questions.
> > Ben
> > 
> > 
> > --- In [email protected], "phipzkillah" <pkrasko@> wrote:
> > >
> > > Thanks for your reply Ben.
> > > 
> > > I have a few more questions, hopefully you can help.  The
> > > "doCoolStuff", is that the method we are trying to call through the
> > > web service?  From your example it seems like you can specify
> > > operation arguments in either an object or array format.  I don't
> > > think I fully understand how the web service works interprets
that...
> > > 
> > > If a method requires certain parameters (ie: name:String,
age:Number)
> > > how would you go about passing those in as arguments??
> > > 
> > > op.arguments.objectArg = {name: "John Doe", age: 26}  ??
> > > 
> > > How do you specify the result format to be e4x?
> > > 
> > > Help would be appreciated.
> > > 
> > > -phil
> > > 
> > > 
> > > --- In [email protected], "ben.clinkinbeard"
> > > <ben.clinkinbeard@> wrote:
> > > >
> > > > I've not dealt with authentication but here is how to call an
> > operation.
> > > > 
> > > > // getOperation() returns generic AbstractOperation by default
> > > > // you want mx.rpc.Operation, not mx.rpc.mxml.Operation
> > > > var op:Operation = ws.getOperation("doCoolStuff") as Operation;
> > > > op.arguments.arrayArg = new Array("foo", "bar");
> > > > op.arguments.objectArg = {propA: "tweedle", propB: "dee"};
> > > > op.send();
> > > > 
> > > > You can optionally capture the token created by the call and
> assign a
> > > > responder as well:
> > > > 
> > > > var call:ASyncToken = op.send();
> > > > call.addResponder(IResponder);
> > > > 
> > > > The IResponder interface defines a result and fault method
that are
> > > > called when the operation returns.
> > > > 
> > > > HTH,
> > > > Ben
> > > > 
> > > > 
> > > > 
> > > > --- In [email protected], "phipzkillah" <pkrasko@> wrote:
> > > > >
> > > > > Hi,
> > > > > 
> > > > > I am trying to create a web service in pure action script.  I
> > need to
> > > > > authenticate and then call the proper method from the web
service.
> > > > > 
> > > > > I have not seen any good tutorials explaining how to do this...
> > > > > 
> > > > > This is my current snippet:
> > > > > 
> > > > > private function init():void{
> > > > >                       
> > > > >      var ws:WebService = new WebService;
> > > > >                       
> > > > >      ws.wsdl =
> > > > > "http://sc-vmx-03/clarusipc/services/InventoryService?wsdl";;
> > > > >      ws.useProxy = false;    
> > > > > 
> > > > >     
> > > > >
> > > >
> > >
> >
>
ws.loadWSDL("http://sc-vmx-03/clarusipc/services/InventoryService?wsdl";);
> > > > > 
> > > > > }
> > > > > 
> > > > > What is the format to add in an operations object that will
> include
> > > > > the method and parameters that I'm going to call?
> > > > > 
> > > > > How would I go about editing the http request to include a
> username
> > > > > and password to authenticate against?
> > > > > 
> > > > > Any help would be greatly appreciated!!!  It's driving me nuts!
> > > > >
> > > >
> > >
> >
>


Reply via email to