Handling client disconnect in duplex WCF service
Im trying to get a WCF service to know when a client has disconnected.
After reading this article wcf notification on disconnect I managed to get a test project working.
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.
<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 Operatio开发者_如何学JAVAnContext.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.
Things I have noticed that are different is the fact that I cannot specify an enabled="true" property in the config. Also the second project uses WSDualHTTPBinding whereas the first one uses 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. 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. 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.
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?
精彩评论