how to make web service return response, and then keep processing the request

  • Thread starter Secret Squirrel
  • Start date
S

Secret Squirrel

Hi,

How can I make a web service return a response, and then keep
processing the request?

For example, a client calls a WS to request the server do a time
consuming calculation. The web service should return a response
indicating the processing has begun, and then continue processing the
request. Response first, then more execution.

Thanks,

Jon Paugh
 
C

CESAR DE LA TORRE [MVP]

You can use Asyncronous execution of Web Services. Take a look of the
following:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service10012002.asp

http://www.codeproject.com/cs/webservices/async_xmlws.asp

Take into account that your presentation tier must be able to wait for the
async end-process event. For instance, a WinApp-WinForms can wait for that
and-event. A Windows Service can also wait for that end-event, but a ASP.NET
web page as UI, should cannot wait for the event within the sever execution,
as the execution of a ASP.NET page must be done once and fast. It cannot be
waiting unless you use any Client Script (like AJAX/ATLAS, based on client
JScript) calling to the Web Service.

Regards,

--
CESAR DE LA TORRE
Software Architect
[Microsoft MVP - XML Web Services]
[MCSE] [MCT]

Renacimiento
[Microsoft GOLD Certified Partner]
 
P

Peter Kelcey

Jon

I believe I understood your question a little differently than Cesar
did. As I understand it, you want the client to call the server
synchronously and have the web service respond immediately. Then you
want the web service to kick a new set of code after the response to
the client has been made. You don't want your client to have to worry
about any asynchronous actions.

In that case, you don't want to use an asynchronous web service call.
Just call your web service as you normally do, but have you web service
spawn a new thread that will launch the asynchronous code. I've
included an example below.

<WebMethod()> _
Public Function HelloWorld() As String
'create your new thread
Dim thread As New System.Threading.Thread(AddressOf
RunAsync_Proc)

'start the async thread
thread.Start()

'respond to your client while the other thread is still running
Return "Hello World"
End Function

Public Sub RunAsync_Proc()

'Put code here to do your asynchronous processing

End Sub


If you're interested, there is another option. You could potentially
use the SOAPDocumentMethodAttribute.OneWay property that is already
built into the .NET framework . It allows you to create web services
that automatically respond to the client before they begin their own
processing.

You can read more about this property at

http://msdn.microsoft.com/library/d...apdocumentmethodattributeclassonewaytopic.asp

Hope that helps.

Peter Kelcey
 
C

CESAR DE LA TORRE [MVP]

Yes, indeed. If the caller does not need any 'end-work-response' about the
WebService execution, (end-value post-execution, etc.), if it is not waiting
for that, then, for sure, I agree.

The answer the client App. is gonna get will be just an 'ACK', I mean,
something saying it just started to work (but take into account that the
caller will not know if that background thread/job finished properly. Also,
you will not know when it finished). If that is OK for you, I completly
agree with Peter.
It would be like using messages with MSMQ (Microsoft Message Queue Service)
without 'end-of-work-responses' messages. You just send a message and you
trust that the other point will execute something.
--
CESAR DE LA TORRE
Software Architect
[Microsoft MVP - XML Web Services]
[MCSE] [MCT]

Renacimiento
[Microsoft GOLD Certified Partner]
--
CESAR DE LA TORRE
Software Architect
[Microsoft MVP - XML Web Services]
[MCSE] [MCT]

Renacimiento
[Microsoft GOLD Certified Partner]
 
S

Secret Squirrel

Thanks for the suggestion Cesar and Peter.

Unfortunately, I have tried what you suggested previously and it's not
working. I do create a thread for the "time consuming process", start
it, and return the response. The problem is that in the "time consuming
process" thread, an error occurs:

System.Threading.ThreadAbortException: Thread was being aborted.

It seems like when the web service returns its response, this other
thread is getting aborted? I will test some simpler examples. It sounds
like this should NOT be happend?

Thanks,

Jon Paugh
 
S

Secret Squirrel

i figured it out - executing from my WS my code works just fine. But
executing from NUNit, my test fails. Apparently NUnit kills all child
threads when test is completed.

Thanks Again,

Jon Paugh
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top