I have a few WCF calls, lets say A, B, C, D, E. They are in a SL application (so I guess I have to be careful with threading and such).
I want B to run after A has completed, while C can run concurrent with them. I want D to run after all three of them finished. And additionally based on a condition (simple if…) I want E to run too (concurrent with any of the above).
I just downloaded Rx and feel that it is the tool for this job. However I don’t yet grasp all the operators and the tricks and such.
Can this be done? How? Please explain the operators required for this.
EDIT to add: For simplicity’s sake let’s say all of these services take a string (or an int) as a parameter, and returns something which implements a complex interface, so the events are simple EventHandlers (non-generic), and I cast them to their special interface in the handler code.
Some inputs are available at the start, some come from result of previous services (e.g. B’s input string is computed based on A’s result)
I’ve taken the edit into account and put together a solution.
I do have to say that Microsoft has made it awfully hard to write simple WCF calls in Silverlight. Handling events to get the return data from async calls is just painful.
Having said that, with a little bit of “copy-and-paste” boiler-plate code, Rx does a great job of removing the complexity.
Here’s what I came up with as the final client code:
On one hand this code isn’t as pretty as I had hoped, but on the other I don’t think I could get it any better. Hopefully you can see how your requirements are being met.
Now for the bad news – the extension methods must be created for every service proxy. The way the
EventArgsare defined there is no way to get the results out without using the specific service reference class as thethisparameter for the extension methods.On the plus side though the code is mostly “copy-and-paste” with very little modification.
Also, you do need to create as many extension methods as many parameters you use plus one.
Here are the extension methods I needed to define for my sample code:
Like I said, painful.
You certainly don’t have to create these type of extension methods to use Rx with WCF in Silverlight, but it’s my feeling that once you have created them then the client code becomes much, much easier to work with.
Let me know if you need more explanation on anything.