首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用http keepalive的WCF wsHttpBinding

使用http keepalive的WCF wsHttpBinding
EN

Stack Overflow用户
提问于 2011-06-30 20:54:54
回答 2查看 13.2K关注 0票数 12

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

我希望我可以通过更改客户端配置来打开它...我已经找到了很多关于如何为basicHttp绑定打开keep-alives的描述,但在wsHttpBinding上却一无所获……这个是可能的吗?

非常感谢。

下面是我的客户端绑定:

代码语言:javascript
复制
  <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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-30 21:25:33

您必须使用custom binding来禁用Keep-Alive头,因为该特性不会在任何内置绑定类中公开。

要实现这一点而不必从头开始定义自定义绑定,最简单的方法是在代码中自定义与客户端代理关联的现有BasicHttpBindingWSHttpBinding实例。

下面是一个例子:

代码语言:javascript
复制
var proxy = new MyServiceClient();
var customBinding = new CustomBinding(proxy.Endpoint.Binding);
var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
transportElement.KeepAliveEnabled = false;

proxy.Endpoint.Binding = customBinding;
票数 24
EN

Stack Overflow用户

发布于 2011-06-30 21:25:44

默认情况下,所有基于HTTP的绑定都启用了Keep alive,并且无法将其关闭。如果要将其关闭,则必须创建全新的自定义绑定,并在httpTransport绑定元素上将keepAliveEnabled设置为false。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6535074

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档