使用IIS托管的WCF处理长时间运行的服务操作的正确方法是什么? [英] What is the correct way to handle long running service operations with WCF hosted in IIS?

查看:35
本文介绍了使用IIS托管的WCF处理长时间运行的服务操作的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个WCF服务,它将公开一些操作,它将在IIS中运行,因为它需要HTTPS终结点.大多数操作将在几秒钟或更短的时间内执行;但是,这些操作中的一两个操作将花费5-90分钟.

I am building a WCF service that will expose several operations, it will run in IIS because it needs HTTPS endpoints. Most of the operations will perform within seconds or less; however, one or two of these operations will take between 5-90 minutes.

此服务的主要使用者将是ASP.NET MVC应用程序;处理此问题的正确方法是什么?

The primary consumer of this service will be an ASP.NET MVC application; what is the correct way to do handle this?

我应该增加超时时间并进行一些ajax调用吗?我应该在我的数据库中添加一个表,并通过长时间运行的操作来更新该数据库,并让Web界面每分钟轮询一次该表吗?我不确定是否有普遍接受的最佳做法.

Should I jackup the timeout and do some ajax calls? 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? 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. 我选择走在数据库中存储工作"的状态"的路径.
  2. 我编写了一个管理器Windows服务,该服务实现了WCF客户端(代理)
  3. 我编写了实现我的工作主持人"的WCF服务.

管理器服务将从数据库中读取队列,然后将工作分发给我的所有工作主机".之所以让Windows服务执行此任务,而不是让UI直接与工作主机对话,是因为它对整个过程提供了更高级别的控制.

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服务使我能够不断监视WCF工作主机的进度,并且如果曾经发生连接错误(或其他意外情况),我可以将状态更新为失败.因此,没有孤立的工作.

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. Thus, no orphaned jobs.

这篇关于使用IIS托管的WCF处理长时间运行的服务操作的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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