简体   繁体   English

如何使WCF RESTful服务异步工作?

[英]How to make WCF RESTful service work async?

I'm building WCF rest service and it's client. 我正在构建WCF休息服务,它是客户端。 I plan, that client does not know much about the service, just right URL's to call methods and expected results. 我计划,该客户对服务知之甚少,只是正确的URL即可调用方法和预期结果。

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实现如下:

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. 问题是-在所有SubmitTask操作都已完成的同时,未在服务端执行GetTask,因此我仅在客户端获得最后一个任务状态。 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 调整WCF以构建高度可扩展的异步REST API ,下面的文章非常好,有望为您提供所需的答案。 修复WCF以构建高度可扩展的异步REST API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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