Search code examples
c#.netweb-servicesasynchronouslong-polling

Is it possible to implement Async Webservice call in .Net not only by one connection?


I have a .net Webservice. It has a method that does a task that takes 60 seconds and after that, returns the string result to client.

In some networks especially low band widths I get timeout error in 40 seconds before webservice method do its task in 60 second.

Now I want to implement webservice Async call to support low band width networks.

In Async webservice call an approach is using a thread that runs webservice method and returns webservice result to main thread that is shown in the following picture.

enter image description here

But my problem will not be solved in this approach because that thread uses one connection.

I need another approach. A thread in my client call webservice method and method starts its operation and when the task is done, 1) webservice sends a message that your response is ready or, 2) client checks if the webservice response is ready (I think polling mechanism) like the following picture.

enter image description here

How can I implement the second approach in .net? Is it possible?

Thanks.


Solution

  • Create a table on your database to store the state of the process.

    UniqClientId, ProcessId, StartTime, EndTime and any other state if required.
    
    1. Client sends a request to the server by passing its unique id.
    2. Server logs the process on the above table and initiates the process.
    3. Clients contacts the server instantly(2-3 sec or 15-20 sec depending on your application) to check the process completion.
    4. If the client get a response that process has been completed, then it requests the server to send the response.

    In between, the server does the following job.

    1. When the process completes, stores the EndTime on above table.
    2. Provides a method to send the process state by checking the above table.
    3. Provides a method to send the response.

    I'm not sure what exactly your service is doing, but if the operation of your process is just to modify some table on the database, then is is not difficult to implement this.