PDA

View Full Version : Calling a web service proxy asynchronously


dsmalley
10-23-2007, 08:32 PM
I was wondering if there is any accepted "best practice" for calling the methods of a dynamically generated web service proxy? I'm referring to the product of WebServiceProxyFactory when "ProxyType" (a VS-generated proxy class) is not used.

The generated proxy implements the service interface, but of course doesn't include any methods like Begin<methodname>, End<methodname>, or <methodname>Async, since those methods don't exist on the actual service object.

It is possible to use the standard delegate-based pattern for calling a synchronous method asynchronously, but I was wondering if there are any other possibilities?


Dave

Bruno Baia
10-25-2007, 02:39 PM
Hi,

Unfortunately, WebServiceProxyFactory does not generate asynchronous methods when using dynamically generated web service proxy.

- Bruno

dsmalley
10-25-2007, 04:06 PM
Well, I knew it wasn't supported directly. Actually, after thinking about it, it makes a kind of sense. If one is going to code to an interface, auto-generating async methods would be problematic anyway; it's not clear to me how you would call them in user code other than through reflection.

For my own purposes, I have ended up treating it in a web service agnostic way. Suppose I have a math library, with methods to perform long-running calculations. Even if it is a local object, calculating the millionth prime will take awhile. So, I would need to implement my own threading anyway.

I was able to get what I wanted in a Windows Forms application by dispatching my calls to the proxy with a BackgroundWorker. This actually turned out to be cleaner than some code I wrote before using async calls and completed event handlers with VS 2005 generated proxies. Thanks,

Dave