Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / October 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Secret Squirrel - 06 Oct 2005 22:31 GMT
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
CESAR DE LA TORRE [MVP] - 07 Oct 2005 10:03 GMT
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,

Signature

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

Renacimiento
[Microsoft GOLD Certified Partner]  

> Hi,
>
[quoted text clipped - 9 lines]
>
> Jon Paugh
Peter Kelcey - 07 Oct 2005 20:49 GMT
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/default.asp?url=/library/en-us/cpref/html/frlr
fsystemwebservicesprotocolssoapdocumentmethodattributeclassonewaytopic.asp


Hope that helps.

Peter Kelcey
CESAR DE LA TORRE [MVP] - 10 Oct 2005 11:27 GMT
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.
Signature

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]  

> Jon
>
[quoted text clipped - 42 lines]
>
> Peter Kelcey
Secret Squirrel - 12 Oct 2005 16:05 GMT
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
Secret Squirrel - 12 Oct 2005 19:49 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.