【问题标题】:WCF wsHttpBinding with http keepaliveWCF wsHttpBinding 与 http keepalive
【发布时间】:2011-09-25 23:28:05
【问题描述】:

我有一个使用 wsHttpBinding 的 WCF 客户端,我想启用 http keep-alive。

我希望我可以通过更改客户端配置来打开它...我发现很多关于如何为 basicHttp 绑定打开 keep-alives 的描述,但是 wsHttpBinding 没有运气...这可能吗?

非常感谢。

这是我的客户端绑定:

  <wsHttpBinding>
    <binding name="WSHttpBinding_IRepositoryService" closeTimeout="00:00:10"
      openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxReceivedMessageSize="655360" messageEncoding="Mtom"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="81920" maxArrayLength="163840"
        maxBytesPerRead="409600" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="true" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="">
          <extendedProtectionPolicy policyEnforcement="Never" />
        </transport>
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
          algorithmSuite="Default" establishSecurityContext="true" />
      </security>

    </binding>
</wsHttpBinding>

【问题讨论】:

    标签: .net wcf configuration keep-alive


    【解决方案1】:

    您必须使用custom binding 来禁用Keep-Alive 标头,因为该功能未在任何内置绑定类中公开。

    无需从头开始定义自定义绑定即可实现此目的的最简单方法是在代码中自定义与客户端代理关联的现有BasicHttpBindingWSHttpBinding 实例。

    这是一个例子:

    var proxy = new MyServiceClient();
    var customBinding = new CustomBinding(proxy.Endpoint.Binding);
    var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
    transportElement.KeepAliveEnabled = false;
    
    proxy.Endpoint.Binding = customBinding;
    

    【讨论】:

    • 在这种情况下,不必在服务器端应用相同的配置。 Keep alive 是 HTTP 传输功能,如何配置取决于每个参与者。
    • @Ladislav Mrnka 绝对正确。但是,此设置可以应用于服务器。我更新了我的答案。
    • 非常感谢。我没有意识到默认情况下启用了keepalives,所以这对我来说是一件少做的事情:)
    【解决方案2】:

    默认情况下,所有基于 HTTP 的绑定都启用保持活动,并且无法将其关闭。如果你想关闭它,你必须创建全新的自定义绑定,并在 httpTransport 绑定元素上将 keepAliveEnabled 设置为 false。

    【讨论】:

    • 需要明确的是,不可能在基于 http 的内置绑定(basicHttpBinding、wsHttpBinding 等)上关闭 keep-alive,因为这些绑定不公开属性。它可以在自定义绑定中关闭。我知道这就是你所说的,但你的措辞令人困惑,我想澄清一下。
    猜你喜欢
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多