WCF的wsHttpBinding以http存活 [英] WCF wsHttpBinding with http keepalive

查看:274
本文介绍了WCF的wsHttpBinding以http存活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF客户端,它使用的wsHttpBinding,我想启用HTTP保持活动。

我希望我可以只是改变了客户端配置打开这个...我发现很多如何打开保持有效指示的basicHttp约束力的描述,但没有运气的wsHttpBinding ...是这可能吗?

非常感谢。

下面是我的客户端绑定:

 <的wsHttpBinding>
    <绑定名称=WSHttpBinding_IRepositoryServicecloseTimeout =00:00:10开始
      openTimeout =00:00:10receiveTimeout =00:05:00的SendTimeout =00:05:00
      bypassProxyOnLocal =假transactionFlow =假hostNameComparisonMode =StrongWildcard
      maxBufferPoolSize =524288maxReceivedMessageSize =655360messageEncoding =MTOM
      textEncoding =UTF-8useDefaultWebProxy =真allowCookies =假>
      < readerQuotas MAXDEPTH =32maxStringContentLength =81920maxArrayLength =163840
        maxBytesPerRead =409600maxNameTableCharCount =16384/>
      <有序的ReliableSession =真正的inactivityTimeout =00:10:00
        启用=真/>
      <安全模式=消息>
        <交通运输clientCredentialType =窗口proxyCredentialType =无
          境界=>
          < extendedProtectionPolicy policyEnforcement =从不/>
        < /运输>
        <消息clientCredentialType =窗口negotiateServiceCredential =真
          algorithmSuite =默认establishSecurityContext =真/>
      < /安全>

    < /装订>
< /的wsHttpBinding>
 

解决方案

您将不得不使用以禁用保持活动头,因为该功能不会在任何暴露的自定义绑定内置绑定类。

要实现这一目标,而无需自定义一个从无到有结合最简单的方法,就是自定义现有的<一个href="http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding.aspx">BasicHttpBinding或<一href="http://msdn.microsoft.com/en-us/library/system.servicemodel.wshttpbinding.aspx">WSHttpBinding实例相关联的在code中的客户端代理。

下面是一个例子:

  VAR代理=新MyServiceClient();
VAR customBinding =新CustomBinding(proxy.Endpoint.Binding);
变种transportElement = customBinding.Elements.Find&其中; HttpTransportBindingElement&GT;();
transportElement.KeepAliveEnabled = FALSE;

proxy.Endpoint.Binding = customBinding;
 

I have a WCF client which uses a wsHttpBinding, I would like to enable 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?

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.

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.

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;

这篇关于WCF的wsHttpBinding以http存活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆