简体   繁体   English

处理双工WCF服务中的客户端断开连接

[英]Handling client disconnect in duplex WCF service

Im trying to get a WCF service to know when a client has disconnected. 我试图获得一个WCF服务,以了解客户端何时断开连接。

After reading this article wcf notification on disconnect I managed to get a test project working. 在阅读本文后, 关于断开连接的wcf通知我设法让测试项目正常工作。

The client and server remain open until I close the client, then the OperationContext.Current.Channel.Closed event seems to fire after the timeout in the line below expires. 客户端和服务器保持打开状态,直到我关闭客户端,然后在下面的行中超时后,OperationContext.Current.Channel.Closed事件似乎触发。

<reliableSession enabled="true" ordered="true" inactivityTimeout="00:01:00" />

After testing this worked as I wanted I then tried to integrate it into a larger project I have. 经过测试后,我按照自己的意愿工作,然后尝试将其集成到一个更大的项目中。

This seems to behave differently in that the OperationContext.Current.Channel.Closed even fires after the time specified in the config <reliableSession ordered="true" inactivityTimeout="00:01:00" /> even when the client is still open. 这似乎表现不同,因为即使客户端仍处于打开<reliableSession ordered="true" inactivityTimeout="00:01:00" /> ,OperationContext.Current.Channel.Closed甚至会在config <reliableSession ordered="true" inactivityTimeout="00:01:00" />指定的时间后触发。

Things I have noticed that are different is the fact that I cannot specify an enabled="true" property in the config. 我注意到的不同之处在于我无法在配置中指定enabled =“true”属性。 Also the second project uses WSDualHTTPBinding whereas the first one uses WSHTTPBinding. 第二个项目使用WSDualHTTPBinding,而第一个项目使用WSHTTPBinding。

My question is why is the second project behaving in this way and how can I get it to behave like the first one? 我的问题是为什么第二个项目以这种方式表现,我怎么能让它像第一个一样?

If you need any code files or configs posting please let me know and I'll get them straight up. 如果您需要任何代码文件或配置发布,请告诉我,我会直接让他们。

Kind Regards 亲切的问候

Ash

The HTTP Protocol is inherently stateless and purely request/reply. HTTP协议本质上是无状态的,纯粹是请求/回复。 How WSDualHTTPBinding works is that it opens channels on both the server and the client, when the server is ready to send a message it will use the channel that is hosted by the client to sent the message. WSDualHTTPBinding的工作原理是它在服务器和客户端上打开通道,当服务器准备发送消息时,它将使用客户端托管的通道发送消息。 So what might be happening is that the connection on the client is opened nothing is heard for a minute this is detected as "inactive" and then the client closes the connection. 所以可能发生的事情是客户端上的连接被打开,没有听到一分钟,这被检测为“非活动”,然后客户端关闭连接。 I'm not sure what your requirements are but you might want to consider switching to TCPBinding since that is a stateful connection. 我不确定您的要求是什么,但您可能要考虑切换到TCPBinding,因为这是一个有状态连接。

Is the client able to receive messages from the server? 客户端是否能够从服务器接收消息? Do the messages get sent regularly? 消息是否定期发送? Are you sure that the client is actually holding the connection open? 您确定客户端实际上是否保持连接打开状态?

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

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