如何判断基于 NetTcp 的 WCF 连接已中断?

发布于 2024-08-25 03:39:42 字数 236 浏览 9 评论 0原文

WCF 服务基于 NetTcpBinding。客户端可能会悄无声息地消失,让服务器不知道它已不再连接。

我目前正在使用一个线程来 ping 所有连接的客户端以查看它们是否仍然存在,并删除断开连接的客户端。

  • ping 线程是解决问题的正确方法吗?还是有更好的、可能基于事件的方法?
  • 我是否必须通过 try/catch 包围与客户端通信的每个代码,并将其从连接的客户端列表中另外删除?

A WCF service is based on NetTcpBinding. It may happen that a client silently vanishes, leaving the server without knowledge that it is not connected anymore.

I'm currently using a thread that pings all connected client to see if they are still alive, and removes disconnected clients.

  • Is a ping thread the correct way to solve the issue, or is there a better, possibly event-based way?
  • Do I have to surround every code that communicates with the client by try/catch and remove it from the list of connected clients additionally?

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

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

发布评论

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

评论(1

情未る 2024-09-01 03:39:42

我相信我自己找到了答案。

有一个事件 OperationContext.Current.Channel.Closing 在出现故障和关闭的连接时触发。

I believe I found the answer myself.

There is an event OperationContext.Current.Channel.Closing that is fired on faulted as well as closed connections.

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