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

Discussion in 'ASP .Net Web Services' started by Secret Squirrel, Oct 6, 2005.

  1. 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
     
    Secret Squirrel, Oct 6, 2005
    #1
    1. Advertising

  2. RE: how to make web service return response, and then keep processing

    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]


    "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
    >
    >
     
    CESAR DE LA TORRE [MVP], Oct 7, 2005
    #2
    1. Advertising

  3. Secret Squirrel

    Peter Kelcey Guest

    Re: how to make web service return response, and then keep processing

    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
     
    Peter Kelcey, Oct 7, 2005
    #3
  4. Re: how to make web service return response, and then keep process

    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/d...apdocumentmethodattributeclassonewaytopic.asp
    >
    > Hope that helps.
    >
    > Peter Kelcey
    >
    >
     
    CESAR DE LA TORRE [MVP], Oct 10, 2005
    #4
  5. Re: how to make web service return response, and then keep processing

    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, Oct 12, 2005
    #5
  6. Re: how to make web service return response, and then keep processing

    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
     
    Secret Squirrel, Oct 12, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. L-E Eriksson
    Replies:
    2
    Views:
    315
    L-E Eriksson
    Feb 21, 2007
  2. Leo Violette
    Replies:
    0
    Views:
    1,055
    Leo Violette
    Apr 17, 2009
  3. Replies:
    0
    Views:
    297
  4. Dima67
    Replies:
    1
    Views:
    985
    Bob Barrows
    Aug 28, 2009
  5. Replies:
    4
    Views:
    546
    cwdjrxyz
    Jan 17, 2006
Loading...

Share This Page