Calling Async object within a webservice method


Paul Hadfield


From reading various articles on scalability issues, I understand that there
is only a finite number of ASP.NET worker threads and any long running task
within ASP.NET should be fired off on a seperate thread using an async call.
All the articles I can find are either on implementing an async webpage, or
calling an async webservice. I can not however find any article on how to
make calls within a webservice asynchronous. Consider the following:

public int LongRunningTask(int inputValue)
BusinessObject bo = new BusinessObject();
return bo.Process(inputValue); // This typically takes 1-10 seconds,
but could take up to one minute!

Now "BusinessObject" implements the Microsoft "Asynchronous Design Pattern",
having "BeginProcess()" and "EndProcess()" methods, implementing callback,
IAsyncResult and state. But how do you call this in the web method? Is
there any way to hide the fact from the webservice consumer that the call to
the business object is asynchronous? Unlike Page, the base class WebService
doesn't appear to expose any ability to register call backs for any sort of
async call.

My gut feel is that the above is not possible, therefore I have to make the
webservice webmethod asynchronous (i.e. have webmethods
"BeginLongRunningTask" and "EndLongRunningTask"). How do I implement this,
hiding the non-async LongRunningTask() webmethod, as I won't want anyone to
consume that webmethod.


- Paul.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question