Question

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.

Was it helpful?

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.

OTHER TIPS

You can create a one-way WebMethod to submit the intial calculation request. Inside your calculation code, you need to update a database table or similiar with progress, either percentage or completion.

You will then need to create an additional 'Polling' method that you can use to check the status, using the previous table.

When your calculation method marks it as complete, you can then call a final 'GetResults' method which will do just that.

We do something similiar for large file imports that are submitted via web services and it works very well.

Some info;

http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapdocumentmethodattribute.oneway(v=vs.71).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top