如何限制WCF服务的请求执行时间?

发布于 2024-09-03 06:31:10 字数 192 浏览 2 评论 0原文

WCF 配置中是否有某些内容定义了在服务端执行请求的超时?例如,WCF 服务将在一段时间后停止执行请求。我有一项服务,可以根据客户的输入进行一些工作。在某些情况下,此类调用可能会花费太多时间。我想限制服务端此类请求的执行时间,而不是使用 SendTimeout 的客户端。我知道 OperationTimeout 属性,但它不会中止服务请求,它只是告诉客户端请求已超时。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏天碎花小短裙 2024-09-10 06:31:10

一般来说,没有什么可以完全强制执行这一点。不幸的是,这是运行时无法真正很好地执行的事情之一,而不会导致状态混乱(几乎唯一的选择是中止正在运行的线程,这会产生一系列不良后果)。

因此,基本上,如果这是您想要主动强制执行的事情,那么最好设计您的服务来处理此问题,以便您的操作执行具有安全的中断点,如果超过最大执行时间,则可以终止操作。

尽管需要做很多工作,但从长远来看,您可能会对此更加满意。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文