Search the web
Sign In
New User? Sign Up
flexcoders · RIA Development with Adobe Flex
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Reusing HTTPService   Message List  
Reply | Forward Message #127740 of 150927 |
Hi,

I'm re-using an instance of HTTPService, changing the request
arguments to get different responses from the server. But I found
that if, for instance, I made 3 calls this way with the HTTPService,
each of the 3 result handlers registered for each call is executed
every time a result returned.

I solved this by storing a reference to the unique AsyncToken returned
by each service call and matching it to the AsyncToken contained in
each ResultEvent's "token" property in order to determine which result
handler to execute.

I'm not terribly happy with this setup. It seems messy. I'd
appreciate any suggestions on how I can reuse an HTTPService instance
without ending up with long switch statements with countless "if
thisAsyncToken then do thisHandler, else if thatAsyncToken then do
thatHandler... and so on".

Thanks much.

LT




Sat Oct 11, 2008 12:34 am

lagos_tout
Offline Offline
Send Email Send Email

Forward
Message #127740 of 150927 |
Expand Messages Author Sort by Date

Hi, I'm re-using an instance of HTTPService, changing the request arguments to get different responses from the server. But I found that if, for instance, I...
lagos_tout
Offline Send Email
Oct 14, 2008
12:41 pm

This is a normal pattern. What about it makes you uncomfortable? You are using a single result handler function, correct? The switch() statement makes...
Tracy Spratt
nts333rd
Offline Send Email
Oct 14, 2008
6:08 pm

Hi, Tracy. Thanks for your response. It's good to hear that others use this solution. Makes me feel like it's not just a stop-gap hack. However, what made me...
lagos_tout
Offline Send Email
Oct 16, 2008
6:25 am

If I were you, I would simply add the requestId into the server's response, so client always knows which request-response pair it handles. This idea lies...
Dmitri Girski
mitek17
Offline Send Email
Oct 16, 2008
5:29 am

Thanks, Dmitri. This is a great idea. Unfortunately though, in this project, I don't have control over what's returned by the server, so I can't add the ...
lagos_tout
Offline Send Email
Oct 16, 2008
6:29 am

No worries. BTW, there is another way of doing it - each request is represented by some object which creates HTTPService and subscribes for the response. ...
Dmitri Girski
mitek17
Offline Send Email
Oct 16, 2008
10:59 am

Yeah, that's a great idea. Kind of like the Command pattern with handlers, right? LT ... by ... response. ... the ... server's ... contained ... which ... "if...
lagos_tout
Offline Send Email
Oct 17, 2008
10:11 am

How about something like this: (note: I've not tried it, just slapped it straight into the email) public class MyClassThatInvokesHTTPServices { //inner helper...
shaun
shaun@...
Send Email
Oct 17, 2008
2:01 pm

... Thanks much. I think this is the solution. It meets my requirements: no long conditionals; one-to-one matching of service calls to fault/result handlers;...
lagos_tout
Offline Send Email
Oct 17, 2008
5:33 pm

I do like this approach - that's what I do when I code using AsyncTokens. In the SDK's trunk depot, we have implemented a different way of using the...
Jeff Vroom
jeffjvroom
Offline Send Email
Oct 17, 2008
6:47 pm

Yes, AsyncToken is dynamic. Example: Invoke send: var oRequest:Object = new Object(); oRequest.Arg1 = "value1"; var callToken:AsyncToken =...
Tracy Spratt
nts333rd
Offline Send Email
Oct 16, 2008
5:56 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help