Is it possible to create a C# web service which can be called asynchronously without the autogenerated client needing to provide a synchronisation via multithreading.
Asked
Active
Viewed 631 times
1 Answers
3
Yes, the auto-generated proxy always contains both synchronous and asynchronous versions of every method. For instance, if the server exposes a method called DoWork
, the proxy will contain both a DoWork
method and a DoWorkAsync
method. When the Async version of the method completes it's work, the proxy raises a completed event, in this case DoWorkCompleted
. The return value from the DoWork
method will be included in the event args .

Steven Doggart
- 43,358
- 8
- 68
- 105
-
Thank you but I'm wondering how the service can callback to the client? I mean – Matt W Jun 14 '12 at 19:23
-
@MattW Did my edit answer your question, or are you still wondering about callbacks? – Steven Doggart Jun 14 '12 at 19:28
-
Thank you, but I'm wondering how the service can callback to the client? I mean: it seems that the client (autogenerated or not) has to handle calling both the DoWork methods, which seems to keep the asynchronous nature in the client. Can the service itself actually call a method on the client? – Matt W Jun 14 '12 at 19:28
-
Sorry, trying to write this on my phone. Trying to understand if the asynchronous power really rests with the server at any time. It appears to rest entirely with the client in one form or another. – Matt W Jun 14 '12 at 19:30
-
No, not if it's a traditional asmx webservice. If it's a WCF service, then yes, it can. The only way for a traditional webservice to call back to the client would be to have some other custom communication scheme such as a callback webservice running on the client. – Steven Doggart Jun 14 '12 at 19:30