如何使 WCF RESTful 服务异步工作? [英] How to make WCF RESTful service work async?

查看:39
本文介绍了如何使 WCF RESTful 服务异步工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建 WCF 休息服务,它是客户端.我的计划是,那个客户对服务了解不多,只知道调用方法和预期结果的正确 URL.

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.

我的服务合同是:

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

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

SubmitTask 是这样实现的:

SubmitTask is realized like:

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

我对客户的期望:

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

问题是-服务端没有执行GetTask,而所有SubmitTask操作都完成了,所以我只在客户端得到最后一个任务状态.这种情况下如何实现异步操作?

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?

提前致谢!

推荐答案

您是否阅读过这篇有趣的小文章?调整 WCF 以构建高度可扩展的异步REST API 和以下非常好的文章,希望能提供您想要的答案 修复 WCF 以构建高度可扩展的异步 REST API

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 RESTful 服务异步工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆