如何限制WCF服务的请求执行时间? [英] How to limit a request execution time of WCF service?

查看:352
本文介绍了如何限制WCF服务的请求执行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WCF配置中有什么定义了在服务端执行请求的超时吗?例如。 WCF服务将在一段时间后停止执行请求。我有一个服务,使一些工作取决于客户端输入。在某些情况下,此类呼叫可能需要很长时间。我想限制这种请求在服务端的执行时间,而不是客户端使用SendTimeout。我知道OperationTimeout属性,但它不会中止服务请求,它只是告诉客户端请求已超时。

解决方案

一般来说,没有什么会完全执行这个。不幸的是,它是那些事情之一,运行时不能真正强制执行,而不可能留下状态混乱(几乎唯一的替代方法是中止正在运行的线程,并有一堆不良后果)。

因此,基本上,如果这是你想要积极执行的东西,那么设计你的服务来处理这个问题会更好,以便你的操作执行有安全的中断点,如果超过了最大执行时间,则可以终止操作。



虽然这还有很多工作,但从长远来看,您可能会更满意。 / p>

Is there something in WCF configuration that defines a timeout for executing a request at service side? E.g. WCF service will stop executing request after some time period. I have a service which make some work depending on client input. In some cases a such call may take too much time. I want to limit the execution time of such requests on service side, not client one using SendTimeout. I know about OperationTimeout property, but it doesn't abort the service request, it just tells a client that the request is timed out.

解决方案

In general terms, there's nothing that will totally enforce this. Unfortunately, it's one of those things that the runtime can't really enforce nicely without possibly leaving state messed up (pretty much the only alternative for it would be to abort the running thread, and that has a bunch of undesirable consequences).

So, basically, if this is something you want to actively enforce, it's a lot better to design your service to deal with this so that your operation execution has safe interruption points where the operation can be terminated if the maximum execution time has been exceeded.

Though it's a lot more work, you'll likely be more satisfied with it in the long run.

这篇关于如何限制WCF服务的请求执行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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