Faulted WCF duplex callback after inactivity - keep alive long-running push notifications

StackOverflow https://stackoverflow.com/questions/20903939

  •  23-09-2022
  •  | 
  •  

Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top