I attempted to perform an async call to a WCF service, using the same
technique for calling an async webservice method (Begin/End
AsyncPattern). This seems to be working ok.
BUT, it works only if I generate and use a proxy using WSDL. This
generates from the contract a single method which appears to the client
as if it is executing synchroniously on the server (which is great).
I prefer *not* to use the generated proxy (i.e. I use ChannelFactory<T>
and the CreateChannel() method), so I cannot use the AsyncPattern (on
the client side) because the interface of my server (which is available
to the client) has only a Begin/End OperationContract exposed.
public interface IServer
[OperationContract(AsyncPattern = true)]
IAsyncResult BeginDoSomething(int data, AsyncCallback callback,
// runtime throws error if the OperationContractAttribute is
placed here, unlike the earlier
// documentation - but it doesn't matter now...
void EndDoSomething(IAsyncResult result);
ChannelFactory<IServer> factory = new ChannelFactory<IServer>(new
BasicHttpBinding(), new EndpointAddress(serverAddress));
IServer server = factory.CreateChannel();
// i want to be able to do this, just like when i use the proxy,
// but naturally i cannot because the IServer doesn't have this method.
Using Reflector and reviewing the generated proxy, I saw that the proxy
inherits from a ClientBase<T>, and performs the call on a
base.InnerProxy, which eventually is created using CreateChannel() -
which seems to me pretty much what I am doing so far. What I'm missing
is how to perform the method call for DoSomething().
BTW: I don't mind a solution which uses "dirty" invocation (such as
reflection etc'). It just when I've iterated over the different methods
available from the remote object on the server, I've received the
Begin/End methods, but no sign of the DoSomething method.
Finally, please don't post answers such as "just use the proxy" etc'. I
know I can use the proxy, but I have my reasons and its quite
reasonable that its possible to invoke a remote async method not
necessarily using the proxy class generated by WSDL.