How to set keep alive interval for HTTP connection in WCF
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?
Take a look here:
http://web.archive.org/web/20080721055556/http://blog.magenic.com/blogs/jons/archive/2007/05/04/The-Tao-of-Microsoft-WCF-CustomBinding-Configuration-Elements.aspx
There is a detailed discussion of manipulating the keep alive property during an http connection.
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?
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;
}
// ...
}
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
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>
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
精彩评论