本文介绍了如何处理WCF客户端断开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何处理WCF客户端断开连接?
How can I handle WCF Client Disconnects ?
我尝试了回调,但似乎仅在客户端通过使用断开连接"按钮清楚地断开连接"时有效.
I Tried CallBacks but it seems to only works when Client Disconnect "clearly" by using a "Disconnect" button for example.
我希望在客户端断开连接时,即使在手动断开连接或客户端进程崩溃的情况下,也能通知我的服务器.
I want my server to be notified when Client got disconnected, even on manual disconnect or client process crash.
推荐答案
使用OperationContext.Current.Channel.Faulted和OperationContext.Current.Channel.Closed事件.
Use the OperationContext.Current.Channel.Faulted and OperationContext.Current.Channel.Closed events.
当客户端出于任何原因断开连接时,就会触发这些事件.
These events are fired when the client has disconnected for whatever reason.
这篇关于如何处理WCF客户端断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!