简体   繁体   中英

How to make WCF RESTful service work async?

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM