如何防止在空闲时段后关闭双工回叫信道?
我的工作主要是duplex WCF setup over NetTcpBinding,即the client can talk to the server and the server can call back to the client。
此外,我使用a reliable session such that the client does not lose the connection获得after the default period of inactivity服务器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;
但是,经过一段不到半小时的不活动时间(没有完全测量到最短时间),服务器再也无法使用回调 - 服务器只会阻塞一分钟左右,我没有看到任何异常,而客户端没有任何事情发生(没有回调的证据)。
请注意,我可以连续两次使用回调,只要我在回调调用之间不等待很长时间。
答案 0 :(得分:1)
我通过扩展BaseClient类来实现这个目的,当没有其他调用时,在目标接口上调用自动保持活动消息。