如何判断基于 NetTcp 的 WCF 连接已中断?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信我自己找到了答案。
有一个事件
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.