Search code examples
wcf-restwebhttpbinding

Long calculation in a wcf restful service


I have a WCF restful service and it works correctly, the problem is that the service expose a method "Calculate" and it may take several minutes to complete the calculation, and since REST is a stateless method, I'm running out of ideas !

should I maintain the session ?

how can I do a callback ?

10 minutes waiting for a response in a website is not convenient, but I have to find a solution.

PS: the service MUST be restful, and I cant reduce the calculation time.


Solution

  • I asked about your clients because if they were .Net only, you could implement the async programming model, but since they aren't...

    You can do something like in this post - WCF Rest Asynchronous Calling Methods

    Basically your method will spawn an additional thread to do the actual calculation work, and return some sort of token to the calling client immediately in the main thread. The client can then use this token in a polling method to check if the calculation is complete.