I am currently developing a REST Service where one of the methods is a long running task (named CalculatePrimeOneWay). Its definition is
[OperationContract(IsOneWay = true)]
[WebInvoke(Method = "POST", UriTemplate = "primeoneway/{jobnumber}")]
void CalculatePrimeOneWay(string jobnumber, Prime prime);
As there is no callback capability with a REST Service, I thought about implementing a kind of polling method to obtain status information. This polling method is defined as
[OperationContract]
[WebGet(UriTemplate = "poll/{jobnumber}")]
Job GetJobStatus(string jobnumber);
I write status information into a MS SQL table.
I start my client and invoke the CalculatePrimeOneWay Method. Subsequent calls to GetJobStatus return a WebException with Protocol Error, Status Code 400 and Status Description Bad Request. However, if CalculatePrimeOneWay is finished and I then invoke GetJobStatus, all works perfectly fine.
Why am I unable to call GetJobStatus while CalculatePrimeOneWay is still running? What other solutions would be possible for my scenario of a long runnning task and a polling mechanism?
Thanks