Http transport channel in WCF uses persistent HTTP connections by default. How to control keep alive timeout for those connections? Default value is 100s. I found that value by monitoring application in Procmon. I haven't found any setting in http transport binding element which configures this timeout. Is there any .NET class which can control that timeout?
6 Answers
Take a look here:
There is a detailed discussion of manipulating the keep alive property during an http connection.

- 2,121
- 1
- 15
- 26

- 48,713
- 13
- 73
- 98
-
2Thanks for post but this doesn't answer the question. Question is not about turning off keep alive but about setting keep alive timeout. So I want to have keep alive turn on and I want to control its duration. – Ladislav Mrnka Aug 23 '10 at 21:22
I found the solution for this. The problem is that the underlying kernel http.sys has it's own timeout and it will break the connection.
http://mmmreddy.wordpress.com/2013/07/11/wcf-use-of-http-transport-sharing-persistent-tcp-sessions/
netsh http add timeout timeouttype=idleconnectiontimeout value=120
Also, this question is similar to this What 130 second timeout is killig my WCF streaming service call?

- 1
- 1

- 1,123
- 8
- 14
It sounds to me like you're wanting to adjust the Keep-Alive
HTTP header. You should read this article on HTTP keep-alive and first determine if this is really something worth your time.
If it is, try creating a Message Inspector. This should allow you to modify the HTTP headers for each message that gets sent out:
public class KeepAliveMessageInspector : IClientMessageInspector
{
// ...
public object BeforeSendRequest(
ref System.ServiceModel.Channels.Message request,
System.ServiceModel.IClientChannel channel)
{
// Add/modify the Keep-Alive header
var httpRequestMessage = new HttpRequestMessageProperty();
httpRequestMessage.Headers.Add("Keep-Alive", "9000");
request.Properties.Add(
HttpRequestMessageProperty.Name, httpRequestMessage);
return null;
}
// ...
}

- 2,121
- 1
- 15
- 26

- 77,566
- 24
- 149
- 228
-
2This idea is interesting. I saw something like that in communication with Cassini but I think it is not standard header. Anyway I will try it during next few days. If it works I will set the new bounty and award you. – Ladislav Mrnka Aug 25 '10 at 22:02
-
Btw. I don't need to use it. I just want to know if it is possible to change it somehow and where the default value 100s comes from. – Ladislav Mrnka Aug 25 '10 at 22:03
-
@Ladislav Mrnka : Sorry to burry out this old post, but have you been able to set or read this HTTP keep-alive value. If yes, I would be very interested in knowing more about it. Thanks – Seb T. Jun 06 '14 at 12:15
-
https://www.io.com/~maus/HttpKeepAlive.html not found ***404 error***, _url broken_ – Kiquenet Oct 13 '16 at 13:43
Setting ServicePoint.MaxIdleTime should let you change the default 100 second idle timeout on the persistent HTTP connections.
https://www.visualbasicplanet.info/windows-communication/configuring-http-connections.html

- 251
- 2
- 9
From this answer, and what I can read here, it looks like you want to create a custom http binding, and set the inactivityTimeout
attribute.
From the MSDN article:
<bindings> <customBinding> <binding name="Binding1"> <reliableSession acknowledgementInterval="00:00:00.2000000" enableFlowControl="true" maxTransferWindowSize="32" inactivityTimeout="00:10:00" maxPendingChannels="128" maxRetryCount="8" ordered="true" /> <security mode="None"/> <httpTransport authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" proxyAuthenticationScheme="Anonymous" realm="" useDefaultWebProxy="true" /> </binding> </customBinding> </bindings>
-
1No. I want to set HTTP keep alive not Reliable session keep alive. HTTP keep alive is described in HTTP protocol specification. – Ladislav Mrnka Aug 24 '10 at 14:17
-
Seems like HTTP connections should always be persistent, as per RFC 2616 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.1). – louisgab Aug 24 '10 at 18:24
-
1I don't think so. The RFC says that HTTP implementation should implement HTTP persistent connections. Not that only persistent connection should be used. – Ladislav Mrnka Aug 25 '10 at 07:34
How about this? Seems it may be a function of your IIS Server and nothing to do with the WCF service? I know this link applies to IIS6, but maybe it serves as a foundation to something similar in IIS7? http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/73566f83-c257-4941-8ed8-7ae45b2e7985.mspx?mfr=true

- 5,642
- 6
- 57
- 88
-
1I have already tryed to set up connection timeout on IIS and it didn't work. It is not related to keep alive setting. Anyway I will try it again during next few days. If it works I will set the new bounty and award you. – Ladislav Mrnka Aug 25 '10 at 22:00