Tell when wcf client lost connection

萝らか妹 提交于 2020-01-01 22:04:12

问题


I have a few computers working as WCF clients and they are connected to a computer who works as the WCF service. Now lets say one client connection is lost (i.e. the cable disconnects), How can I know that happened on the service side? I tried to use the wcf callbacks events Closing/Closed but I did not get the call. I am writing in C#.

Best Regards. Adi.


回答1:


Callbacks dont work because your client cannot tell to service "i'am close connection with you".

What you need is heartbeat - periodic signal generated by your client to indicate normal operation. If service dont recieve this signal from one of clients in time it can guess that this client lost connection.

Also, you need a way to distinguish one client from another on service-side. For examle, every client can pass unique id in heartbeat signal.




回答2:


Your service should not care whether a network cable was disconnected. One feature of TCP is that unless someone is actively sending data, it can tolerate momentary interruptions in network connectivity.

This is even more true in WCF, where there are layers of extra framework to help protect you against network unreliability.

The main thing you would accomplish by attempting to detect disconnection of a client is reduced reliability and availability.



来源:https://stackoverflow.com/questions/27340501/tell-when-wcf-client-lost-connection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!