Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make WCF RESTful service work async?

Tags:

rest

c#

wcf

I'm building WCF rest service and it's client. I plan, that client does not know much about the service, just right URL's to call methods and expected results.

My service contract is:

[WebInvoke(Method="POST", UriTemplate="/tasks")]
[OperationContract]
void SubmitTask(Transaction task);

[WebGet(UriTemplate = "/tasks/{taskId}")]
[OperationContract]
[XmlSerializerFormat]
Transaction GetTask(string taskId);

SubmitTask is realized like:

SubmitTask(Transaction task)
{
   DoSomethingWithTask(task);
   task.Status = "SomeStatus";
   DoSomethingElseWithTaks(task);
   task.Status = "SomeOtherStatus";
}

What I expect on client:

ButtonClick()
{
   SubmitTask(task);
   while(true)
   {
      string status = Transaction GetTask(task.taskId).Status;
      Textbox.Text+= status;
      if(status==ok)
         break;
      Thread.Sleep(1000); 
   }
}

The problem is - GetTask is not performed on service side, while all SubmitTask operations are completed, so I get only last task status on client side. How to realize asynchronos operation performing in this situation?

Thanks in advance!

like image 778
insomnium_ Avatar asked Oct 22 '22 09:10

insomnium_


1 Answers

Have you read this interesting little article? Tweaking WCF to build highly scalable async REST API and the following article that is very good and which will hopefully provide the answer you desire Fixing WCF to build highly scalable async REST API

like image 133
Paul Zahra Avatar answered Oct 24 '22 12:10

Paul Zahra