The documentation around this topic is poor. I use WCF services with NetTcpBinding hosted in Windows service. The problem is that a session is dropped when it is inactive for some time. What I need is the session which is always alive. Is WCF reliable session something that can help? Or I can just play with timeout settings?
Asked
Active
Viewed 3.3k times
2 Answers
47
No, a reliable session will time out just like any other session, too. The main question really is: why on earth do you want your sessions to be "endless" ?? If you really need this, you need to crank up the timeouts on the session.
The point of a reliable session is that the caller will know about any messages that are lost. Contrary to popular belief, the reliable session cannot guarantee delivery of a message - but if a message can't be delivered, at least the caller will know about it.
Check out some of these resources for more background info:

Glorfindel
- 21,988
- 13
- 81
- 109

marc_s
- 732,580
- 175
- 1,330
- 1,459
-
Thanks for clarifying what is reliable session for. Regarding "endless" session: I have an event-driven system. When a message comes the client should call some WCF service. Messages can come each second and it is important to keep up to handle each one. Sometimes the interval between receiving a message can be much greater than one second, say one or two days. So I need some keep-alive mechanism. – Andrei Sedoi May 26 '10 at 09:16
-
1@bsnote: why? If the interval between two messages is two days, there's really no point in having that session up and active all that time, in my opinion.... – marc_s May 26 '10 at 11:24
-
It's too expensive to create a channel each time a message is received in case when messages are received each second. Though I agree that there is no point in having session up when the interval is one day. – Andrei Sedoi May 26 '10 at 15:49
-
2I have a why on earth. Sometimes communication is initiated from the service! If the connection is dropped, this is no good for some purposes because a) we dont know if our service is still alive b) we dont have access to any broadcasts or messages intended for us in specific. But agreed, it looks like cranking up the timeouts. – Josh Sutterfield Apr 18 '13 at 15:35
8
if you dont use the channel, it will close himself after a while. you can change the default timeout (which is 10 min) from the binding.
NetTcpBinding binding = new NetTcpBinding();
binding.ReceiveTimeout = TimeSpan.MaxValue;
binding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
read more at MSDN

avrahamcool
- 13,888
- 5
- 47
- 58