简体   繁体   English

使用IIS中托管的WCF处理长时间运行的服务操作的正确方法是什么?

[英]What is the correct way to handle long running service operations with WCF hosted in IIS?

I am building a WCF service that will expose several operations, it will run in IIS because it needs HTTPS endpoints. 我正在构建一个将公开多个操作的WCF服务,它将在IIS中运行,因为它需要HTTPS端点。 Most of the operations will perform within seconds or less; 大多数操作将在几秒或更短的时间内完成; however, one or two of these operations will take between 5-90 minutes. 但是,这些操作中的一个或两个将需要5-90分钟。

The primary consumer of this service will be an ASP.NET MVC application; 该服务的主要使用者是ASP.NET MVC应用程序; what is the correct way to do handle this? 处理这个问题的正确方法是什么?

Should I jackup the timeout and do some ajax calls? 我应该加满超时并做一些ajax调用吗? Should I add a table to my database, and have the long running operations update this database, and have the web interface poll this table every minute? 我应该向我的数据库中添加一个表,并让长时间运行的操作更新此数据库,并让Web界面每分钟轮询一次这个表吗? I'm not sure what (if there is) the generally accepted best practice for this. 我不确定通常接受的最佳做法是什么(如果有的话)。

I wrote something similar for my senior project, basically a job scheduling framework. 我为我的高级项目编写了类似的东西,基本上是一个作业调度框架。

  1. I chose to go down the path of storing the "status" of the "job" in the database. 我选择在数据库中存储“作业”的“状态”。
  2. I wrote a manager windows service that implemented a WCF client (proxy) 我写了一个实现WCF客户端(代理)的管理器Windows服务
  3. I wrote a WCF Service that implemented my "worker host". 我写了一个实现我的“工作主机”的WCF服务。

The manager service would read the queue from the database, and hand out work to all of my "worker hosts". 管理器服务将从数据库中读取队列,并将工作分发给我的所有“工作者主机”。 The reason I had windows service perform this task as opposed to just having the UI talk directly to the worker host, was because it gave an extra level of control over the whole process. 我有Windows服务执行此任务的原因,而不是直接与工作主机进行UI对话,是因为它对整个过程提供了额外的控制。

I didn't like the idea of having "the network cable unplugged" from my worker host, and never getting a status update again from this specific job. 我不喜欢从我的工作人员主机上拔下“网线拔掉”的想法,并且再也没有从这个特定的工作中再次获得状态更新。 So, the windows service gives me the ability to constantly monitor the progress of the WCF worker host, and if a connection error ever occurs (or something else unexpected), I can update the status to failed. 因此,Windows服务使我能够不断监视WCF工作者主机的进度,如果发生连接错误(或其他意外的事情),我可以将状态更新为失败。 Thus, no orphaned jobs. 因此,没有孤儿的工作。

Take a look at this 看看这个

WCF Long Running Operations There could be other options but they are nearly the same. WCF长期运行可能还有其他选择,但它们几乎相同。 You can also come up with some push notifications (I assume no data is returned) as one int the following link 您还可以在以下链接中提供一些推送通知(我假设没有返回任何数据)

WCF Push WCF推送

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

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