Creating asynchronous WCF clients without using Service References
Currently I do not use Service References as I feel the code it autogenerates is more weight than I need. Instead I generate a proxy class by doing:
public class MyClient : ClientBase<IMyService>, IMyService
This has worked great for me, no proxy classes are generated so I reuse the same datatypes. But this only lets me create synchronous client methods.
What would it take to generate async versions? I have taken a look at the autogenerated code that adding a Service Reference would do and it seems like soo much boilerplate. A ton of begin/end/onbegin/oncomplete assoc开发者_JAVA百科iated event arg datatypes etc etc.
Is there a simpler way with less scaffolding needed to create async client methods? My ultimate end goal is to be able to use the new c# 5 async/await keywords on webservice clients
You can always author a contract IMyAsyncService
that is exactly like IMyService
but uses the Begin/End async pattern (and has [ServiceContract(Name="IMyService")]
to keep the same name). It will be the same wire contract, and work with ClientBase
, but now you have async methods you can use with await
.
I think adding this [OperationContract(IsOneWay = true)]
to your method declaration in the Interface on your services will determine its async.
The CTP for async/await is just a preview of the support for these features. They plan to fully integrate them into WCF.
http://blogs.msdn.com/b/endpoint/archive/2010/11/13/simplified-asynchronous-programming-model-in-wcf-with-async-await.aspx
精彩评论