【发布时间】:2011-03-28 20:18:27
【问题描述】:
默认情况下,WCF 中的 Http 传输通道使用持久 HTTP 连接。如何控制这些连接的保持活动超时?默认值为 100 秒。我通过监视 Procmon 中的应用程序发现了这个价值。我在配置此超时的 http 传输绑定元素中没有找到任何设置。是否有任何 .NET 类可以控制该超时?
【问题讨论】:
默认情况下,WCF 中的 Http 传输通道使用持久 HTTP 连接。如何控制这些连接的保持活动超时?默认值为 100 秒。我通过监视 Procmon 中的应用程序发现了这个价值。我在配置此超时的 http 传输绑定元素中没有找到任何设置。是否有任何 .NET 类可以控制该超时?
【问题讨论】:
【讨论】:
我找到了解决方案。问题是底层内核 http.sys 有它自己的超时,它会中断连接。
http://mmmreddy.wordpress.com/2013/07/11/wcf-use-of-http-transport-sharing-persistent-tcp-sessions/
netsh http add timeout timeouttype=idleconnectiontimeout value=120
另外,这个问题和What 130 second timeout is killig my WCF streaming service call?类似
【讨论】:
在我看来,您想要调整 Keep-Alive HTTP 标头。您应该阅读关于 HTTP keep-alive 的 this article,并首先确定这是否真的值得您花时间。
如果是,请尝试创建Message Inspector。这应该允许您修改发送出去的每条消息的 HTTP 标头:
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;
}
// ...
}
【讨论】:
设置 ServicePoint.MaxIdleTime 应该可以让您更改持久 HTTP 连接的默认 100 秒空闲超时。
https://www.visualbasicplanet.info/windows-communication/configuring-http-connections.html
【讨论】:
从this answer 和我可以读到的here,您似乎想创建一个自定义http 绑定,并设置inactivityTimeout 属性。
来自 MSDN 文章:
<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>
【讨论】:
这个怎么样?似乎它可能是您的 IIS 服务器的功能,与 WCF 服务无关?我知道这个链接适用于 IIS6,但也许它可以作为 IIS7 中类似内容的基础? http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/73566f83-c257-4941-8ed8-7ae45b2e7985.mspx?mfr=true
【讨论】: