如果客户端断开连接,则中止 WCF 服务器任务

发布于 2024-12-28 05:23:34 字数 248 浏览 2 评论 0原文

我们有一个在 Windows 服务下托管的 WCF 服务。该服务的客户端已将 closeTimeout、receiveTimeout、openTimeout、sentTimeout 设置为 5 分钟。服务也同样如此。在某些情况下,WCF 服务可能需要超过 5 分钟来处理任务。在这种情况下,客户端中止调用,但服务进程继续运行直到完成其工作。

现在的问题是...是否有任何可用的配置/技术可以检测客户端已断开连接或超时(或其他原因?)以便 WCF 服务可以中止其任务?

We have a WCF service hosted under Windows service. The client of this service has set up closeTimeout, receiveTimeout, openTimeout, sentTimeout set to 5 minutes. Service also has the same. In certain circumstances, WCF service may take more than 5 minutes to process a task. In this case, client aborts the call, but service process keeps on running until it finishes its job.

Now, the question is... is there any configuration/technique available which would detect that client has disconnected or timedout (or something else?) so that WCF service can just abort its tasks?

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

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

发布评论

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

评论(1

心舞飞扬 2025-01-04 05:23:34

这是 不是 简单,如果不是不可能(所以这几乎是一个重复的问题)。

您真的希望在客户端断开连接时取消操作吗?否则,您可以使用某种工作队列来实现某种类似状态的机制。

然后,客户端调用 QueueQuery(query),它仅执行此操作并将标识符返回到刚刚排队的查询。之后,客户端可以继续轮询QueryStatus(id)来检索状态(例如“Queued”、“Running”、“Finished”),当查询完成时,它可以调用查询结果(id)

与此同时,另一个服务(即 Windows 服务,而不是 WCF 服务)继续执行所有排队的查询。

It's not easy, if not impossible (so this is pretty much a duplicate question).

Do you really want the operation to be cancelled when the client disconnects? Otherwise you could implement some state-like mechanism, using some sort of work queue.

A clients then calls QueueQuery(query), which does nothing more than that and returns an identifier to the just queued query. After that, the client can keep polling QueryStatus(id) to retreive the status (e.g. "Queued", "Running", "Finished"), and when a query has finished, it can call QueryResults(id).

Meanwhile another service (i.e. a Windows service, not a WCF service) keeps executing all queued queries.

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