Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF and inactivity timeout: is it possible to disable the inactivity timeout?

Tags:

wcf

timeout

I have a service that would be running forever, without matter if there is clients or not that access to this service, but after a long time without clients activity, to be able to connect with a client.

This is because for example, after a vacation period, I would like to be able to connect with the service without the needed to restart the service manually.

At the moment, my service is disconnected if it does not receive any connection in 10 minutes, but I don't want to specify any time, I want infinite time.

Thanks.

like image 903
Álvaro García Avatar asked Feb 20 '23 13:02

Álvaro García


2 Answers

You can set inactivityTimeout="infinite", or a very high value, though It's not recommended, your service shouldn't be such that once a client connects to it they can consume it 'forever'.

UPDATE

My mistake, it seems inactivityTimeout can not be set to infinite like other Timeouts such as receiveTimeout.

But why don't you just set receiveTimeout="infinite" ? inactivityTimeout is only used when you have reliableSession enabled, if you don't need reliable sessions, then simply set the receiveTimeout on the binding to infinite, in this case your receiveTimeout is in a way your inactivity timeout. If you must use reliable sessions, then WCF will use both values to determine when your service times out, and both need to be satisfied to keep the connection alive. It seems that the maximum value for inactivityTimeout is '24.20:31:23.6470000', basically 24 days and 20.5 hours, so in the worst case scenario just set your inactivityTimeout="24.20:31:23" which is still a pretty long time, almost a month. If you send your service a simple keep alive message (basically just invoke some operation on your service) in between that period, your connection will be maintained.

like image 178
Mohammad Sepahvand Avatar answered Feb 22 '23 02:02

Mohammad Sepahvand


I'm not sure about other version of .NET, but on 4.5 I was also trying to get around the inactivity period for a WCF service.

On a whim, I set binding.ReceiveTimeout = System.Threading.Timeout.InfiniteTimeSpan, which is a negative timespan. This caused an exception to be thrown with the following interesting tidbit of a message:

System.ArgumentOutOfRangeException: Timeout must be greater than or equal to TimeSpan.Zero. To disable timeout, specify TimeSpan.MaxValue.

So I went back to my code, set the ReceiveTimeout to TimeSpan.MaxValue, and the inactivity timer is now disabled.

like image 41
patrick Avatar answered Feb 22 '23 01:02

patrick