1

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.

Hamza_L
  • 644
  • 4
  • 18

2 Answers2

1

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.

Community
  • 1
  • 1
EkoostikMartin
  • 6,831
  • 2
  • 33
  • 62
  • thanks a lot @EkoostikMartin, it seems to be the best solution, but I wonder how could I implement an async model ( just to find arguments for my bosses :D ) – Hamza_L Jun 27 '12 at 14:10
  • See here - http://www.level533.com/2010/11/uploading-large-files-to-self-hosted-wcf-rest-service/ and here http://stackoverflow.com/a/5959371/903056 - it's not very difficult to accomplish, also it's cool because you can still can the same service synchronously (please mark my answer if it helped you :) ) – EkoostikMartin Jun 27 '12 at 14:27
  • thanks again @EkoostikMartin, it helps a lot (sorry about the mark, I'm new here and I haven't paid attention to marks :D ) – Hamza_L Jun 27 '12 at 15:14
  • 1
    You're welcome, feel free to add any followup questions you have here, I'll try to answer them. – EkoostikMartin Jun 27 '12 at 15:20
0

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

ChrisBint
  • 12,773
  • 6
  • 40
  • 62