简体   繁体   English

WCF wsHttpBinding 与 http keepalive

[英]WCF wsHttpBinding with http keepalive

I have a WCF client which uses a wsHttpBinding, I would like to enable http keep-alive.我有一个使用 wsHttpBinding 的 WCF 客户端,我想启用 http keep-alive。

I'm hoping I can turn this on by just changing the client config... I've found plenty of descriptions of how to turn on keep-alives for a basicHttp binding, but no luck with wsHttpBinding... is this possible?我希望我可以通过更改客户端配置来打开它......我找到了很多关于如何为 basicHttp 绑定打开保持活动的描述,但是 wsHttpBinding 没有运气......这可能吗?

Many thanks.非常感谢。

Here's my client binding:这是我的客户端绑定:

  <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>

You'll have to use a custom binding in order to disable the Keep-Alive header, since that feature is not exposed in any of the built-in binding classes.您必须使用自定义绑定才能禁用Keep-Alive header,因为该功能未在任何内置绑定类中公开。

The easiest way to achieve this without having to define a custom binding from scratch, is to customize the existing BasicHttpBinding or WSHttpBinding instance associated to the client proxy in code.无需从头开始定义自定义绑定即可实现此目的的最简单方法是在代码中自定义与客户端代理关联的现有BasicHttpBindingWSHttpBinding实例。

Here's an example:这是一个例子:

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 is enabled by default on all HTTP based bindings and it is not possible to turn it off.在所有基于 HTTP 的绑定上默认启用保持活动,并且无法将其关闭。 If you want to turn it off you must create whole new custom binding and set keepAliveEnabled to false on httpTransport binding element.如果您想关闭它,您必须创建全新的自定义绑定并将httpTransport绑定元素上的keepAliveEnabled设置为 false。

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

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