views:

185

answers:

2

In Silverlight I got the following problem. If you fire multiple requests to the web service, the responses might not return in an ordered sequence. Meaning if the first request takes longer than the following ones, its response will return at last:

1. Sending request A.. (takes longer for some reason)
2. Sending request B..
3. Sending request C..
4. ...
5. Receiving response B
6. Receiving response C
7. Receiving response A

Now in my scenario, I am only interested in the most recent request being made. So A and B should be discareded and C should be kept as only accepted response.

What is the best approach to manage this? I came up with this solution so far:

Pass a generated GUID as user object when sending the request and store that value somewhere. As all responses will contain their respective GUID, you can now filter out the stale responses. A request-counter instead of a GUID would work as well.

Now I wonder if there are any better approaches to this. Maybe there are any out of the box features to make this possible? Any ideas are welcome..

+2  A: 

I take a similar approach in my non-WCF ASP.NET web services, though I use the DateTime of the request instead and then just store the DateTime of the most recent request. This way I can do a direct less than comparison to determine if the returning service is the most recent or not.

I did look into canceling old service calls before making new ones, but there is no CancelAsync call for web services in Silverlight and I have been unable to find an equivalent way of doing this.

Jeff Yates
A: 

Both of these approaches are what I took when I worked on a real time system with a lot of service calls. Basically just have some way to keep track of order ( incrementing variable, timestamp, etc. ) then keep track of highest received response. If the current response is lower than the highest, drop it.

Jacob Adams