c# - Exposing WCF soap service as async Task<T> from client? -
i'm connecting soap service windows phone 7.1. service proxy has get____async methods , get_____completed events. i'm building service class in client wraps phone call soap service.
can somehow wrap such it's interface becomes:
public nnnnservice { public async task<list<nnnnnn>> getnnnnn(a a, b b, c c) { // ? } }
you can wrap eap tap using next pattern:
public static class nnnnserviceextensions { public static task<returntype> methodnametaskasync(this nnnnservice service, a) { if (service == null) throw new nullreferenceexception(); var tcs = new taskcompletionsource<returntype>(); eventhandlertype handler = null; handler = (s, o) => { service.methodnamecompleted -= handler; tcs.trysetcompleted(o.result); }; service.methodnamecompleted += handler; seek { service.methodnameasync(); } grab { service.methodnamecompleted -= handler; throw; } homecoming tcs.task; } } with optional back upwards cancellation, progress reporting, etc. hard specify homecoming type. in case completed event uses eventargs, can adjust code in next way:
public static task methodnametaskasync(this nnnnservice service, a) { var tcs = new taskcompletionsource<bool>(); } c# windows-phone-7 soap async-await
No comments:
Post a Comment