Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > how to make web service return response, and then keep processing the request

Reply
Thread Tools

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

 
 
Secret Squirrel
Guest
Posts: n/a
 
      10-06-2005
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

 
Reply With Quote
 
 
 
 
CESAR DE LA TORRE [MVP]
Guest
Posts: n/a
 
      10-07-2005
You can use Asyncronous execution of Web Services. Take a look of the
following:
http://msdn.microsoft.com/library/de...ce10012002.asp

http://www.codeproject.com/cs/webser...sync_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]


"Secret Squirrel" wrote:

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

 
Reply With Quote
 
 
 
 
Peter Kelcey
Guest
Posts: n/a
 
      10-07-2005
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/de...newaytopic.asp

Hope that helps.

Peter Kelcey

 
Reply With Quote
 
CESAR DE LA TORRE [MVP]
Guest
Posts: n/a
 
      10-10-2005
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]


"Peter Kelcey" wrote:

> 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/de...newaytopic.asp
>
> Hope that helps.
>
> Peter Kelcey
>
>

 
Reply With Quote
 
Secret Squirrel
Guest
Posts: n/a
 
      10-12-2005
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

 
Reply With Quote
 
Secret Squirrel
Guest
Posts: n/a
 
      10-12-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Does timer in Web Service Global.asax block my Web Service from processing web-site requests? Leo Violette ASP .Net Web Services 0 04-17-2009 12:39 AM
How does one play a .wav file and then another and then another...? ted.j.conway@gmail.com Javascript 4 01-17-2006 03:28 AM
InvocationTargetException when calling "new Service()" in Axis web service to call another web service Michael Averstegge Java 0 01-10-2006 11:05 PM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM



Advertisments