Search code examples
wcftimeout

WCF and inactivity timeout: is it possible to disable the inactivity 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.


Solution

  • 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.