I need to call two operations from a WCF Service that we are consuming from a client. These two operations will be ideally called at the same time, as they both take a few seconds two complete. Once BOTH calls are complete, I’d like to continue with my work in the client. I am a bit stuck what the best model would be for implementing this. Any help or codesamples would be appreciated.
Also: Can I call the methods from the WCF Service in the same method on the client and then wait in this method for the calls to complete? (There isn’t anything else going on in the client during the wait for these two ops to return, so I could wait in the same method that starts the asynchronous calls.)
Using .NET 4.0 / VS 2010 & Visual Basic.
Thanks all!
You may want to think about where you want “control” to sit. For example, you could have the client make two calls, each of which performs one function, or you could have the client make a single call and make the two calls purely on the server.
The guide for this will be how tightly bound you want these two operations to be. Will they always be executed together? If there’s a likelihood that you clients might sometimes just want to execute one of the operations, then it would make sense for there to be two wcf calls, just for flexibility. The client is therefore able to do almost a “pick’n’mix”.
If you decide that the client is the appropriate place to make the two calls, Background Workers may help you.
Either way, by the sounds of things you’re going to need to write some code that sits and waits until two things are done. An approach I have used in the past is to use system events. Check out the method WaitHandle.WaitAll to get an idea of the kind of functionality available to you. These are pretty bulletproof beasties and independent of things like wcf, the downside of then is that they do take up resources so if you’re going to end up with lots of them (several tens) you may want to rethink. But two will not be a problem.