如果客户端断开连接,则中止 WCF 服务器任务
我们有一个在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 不是 简单,如果不是不可能(所以这几乎是一个重复的问题)。
您真的希望在客户端断开连接时取消操作吗?否则,您可以使用某种工作队列来实现某种类似状态的机制。
然后,客户端调用 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 pollingQueryStatus(id)
to retreive the status (e.g. "Queued", "Running", "Finished"), and when a query has finished, it can callQueryResults(id)
.Meanwhile another service (i.e. a Windows service, not a WCF service) keeps executing all queued queries.