代码之家  ›  专栏  ›  技术社区  ›  Ladislav Mrnka

如何在WCF中设置HTTP连接的保持活动间隔

  •  17
  • Ladislav Mrnka  · 技术社区  · 15 年前

    默认情况下,WCF中的Http传输通道使用持久Http连接。如何控制这些连接的保持活动超时?默认值为100秒。我通过监视Procmon中的应用程序发现了这个价值。我在http传输绑定元素中没有找到任何配置此超时的设置。有吗。NET类,哪个类可以控制超时?

    6 回复  |  直到 15 年前
        2
  •  2
  •   Community Mohan Dere    9 年前

    我找到了解决办法。问题是底层内核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?

        3
  •  1
  •   David Archer Chris Spicer    13 年前

    在我看来,你好像想调整 Keep-Alive HTTP头。你应该读 this article 在HTTP上保持活跃,首先确定这是否真的值得你花时间。

    如果是,尝试创建一个 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;
        }
    
        // ...
    }
    
        4
  •  1
  •   wqiu    8 年前

    设置服务点。MaxIdleTime应该允许您更改持久HTTP连接的默认100秒空闲超时。

    https://www.visualbasicplanet.info/windows-communication/configuring-http-connections.html

        5
  •  0
  •   Community Mohan Dere    9 年前

    从…起 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>
    
        6
  •  0
  •   Shawn de Wet    15 年前

    这个怎么样?似乎这可能是您的IIS服务器的功能,与WCF服务无关?我知道这个链接适用于iIS6,但是它可能是IIS7中类似的基础吗? http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/73566f83-c257-4941-8ed8-7ae45b2e7985.mspx?mfr=true

    推荐文章