Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 associated 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

like image 533
puffpio Avatar asked Apr 18 '26 06:04

puffpio


1 Answers

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.

like image 126
Brian Avatar answered Apr 20 '26 19:04

Brian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!