简体   繁体   English

双工WCF捕获客户端断开连接事件

[英]Duplex WCF catch client disconnection event

I've developed a small client/server application with Duplex WCF, but I'm running into a problem trying to detect if client has lost connection to the service. 我已经使用Duplex WCF开发了一个小型的客户端/服务器应用程序,但是在尝试检测客户端是否失去与服务的连接时遇到了问题。

On service side, to detect "dead" clients I simply catch the callback: if fails, then I remove the client from the list. 在服务端,要检测“死”客户端,我只需捕获回调:如果失败,则将客户端从列表中删除。

On client side, how can I detect if client has been disconnected from the server (IE client lost network)? 在客户端,如何检测客户端是否已与服务器断开连接(IE客户端丢失了网络)?

I've tried with 我尝试过

((ICommunicationObject)m_InstContext).Faulted += new EventHandler(ConnectionCrashed);
((ICommunicationObject)m_InstContext).Closed += new EventHandler(ConnectionCrashed);

But seems that it fires only on client => service call, not on callback channel faulted. 但似乎仅在客户端=>服务调用上触发,而在回调通道出现故障时则不会触发。

My client software makes an initial call to the service and then just waits for the server callbacks. 我的客户端软件对服务进行了初始调用,然后仅等待服务器回调。 I've added reliable sessions too, but seems that it's not possible to catch the failed keep-alives as well. 我也添加了可靠的会话,但是似乎也无法捕获失败的保持活动。

Is there any other solution to check if callback channel is still active from client side? 还有其他解决方案可以检查客户端的回调通道是否仍处于活动状态吗?

Thanks 谢谢

解决:我需要检查服务本身而不是InstanceContext上的Faulted / Closed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM