5

In short

How to prevent a duplex callback channel to be closed after an idle period?

In detail

I have a mostly working duplex WCF setup over NetTcpBinding i.e. the client can talk to the server and the server can call back to the client.

Furthermore, I have a reliable session such that the client does not lose the connection to the server after the default period of inactivity, achieved with the following configuration on both client and server:

var binding = new NetTcpBinding(SecurityMode.None);
// Need to prevent channel being closed after inactivity
// i.e. need to prevent the exception: This channel can no longer be used to send messages as the output session was auto-closed due to a server-initiated shutdown. Either disable auto-close by setting the DispatchRuntime.AutomaticInputSessionShutdown to false, or consider modifying the shutdown protocol with the remote server.
binding.ReceiveTimeout = TimeSpan.MaxValue;
binding.ReliableSession.Enabled = true;
binding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;

However, after a period of inactivity of less than half an hour (haven't measured the minimum time exactly), the server is unable to use the callback again - the server just blocks for a minute or so and I do not see any exceptions, while nothing happens on the client side (no evidence of callback).

Leads and root causes?

Note that I can use the callback fine twice in a row consecutively, as long as I do not wait long in between the callback calls.

Community
  • 1
  • 1
Cel
  • 6,467
  • 8
  • 75
  • 110
  • 1
    A simple approach would be to call a simple `KeepAlive` method (example: every minute) from the client using the same proxy instance, so that it actually never becomes idle. – ken2k Jan 03 '14 at 12:59

1 Answers1

1

I achieved this by extending the BaseClient class with an automatic keep alive message to be invoked on the target interface when no other calls are made.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • thanks, will try this unless someone suggests a more preventative measure along the lines of setting inactivity timeouts to gate closing, especially as I need to maintain a number of clients.. – Cel Jan 03 '14 at 13:54
  • & WCF may provide its own keepalive messaging, but Im not sure what values need to used and if this has changed since 2009?: "According to the documentation a Reliable Session would send a keep-alive message after half of the Inactivity Timeout. Unfortunately the expected behaviour was not the same as the actual behaviour.. the Receive Timeout behaviour overrode the keep-alive behaviour" http://www.smartasses.be/2009/01/26/wcf-reliable-session-and-keep-alives/ And furthermore "increasing timeout will keep connections open for failed clients."?? http://stackoverflow.com/a/10172147/742084 – Cel Jan 03 '14 at 14:44