繁体   English   中英

WCF wsHttpBinding 与 http keepalive

[英]WCF wsHttpBinding with http keepalive

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

我希望我可以通过更改客户端配置来打开它......我找到了很多关于如何为 basicHttp 绑定打开保持活动的描述,但是 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>

您必须使用自定义绑定才能禁用Keep-Alive header,因为该功能未在任何内置绑定类中公开。

无需从头开始定义自定义绑定即可实现此目的的最简单方法是在代码中自定义与客户端代理关联的现有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;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM