【问题标题】:WSHttp binding and ReliableSession / MaxRetryCountWSHttp 绑定和 ReliableSession / MaxRetryCount
【发布时间】:2009-12-28 10:13:30
【问题描述】:

在启用了可靠会话的 WCF 中使用 WSHttpBinding 时,我的服务引用会自行更新为:

<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true">
</reliableSession>

只要绑定配置为 WSHttpBinding,我就无法将 maxRetryCount 属性添加到可靠会话。

现在我的问题是:使用 WSHttpBinding 时maxRetryCount 的值是多少,有什么方法可以在配置中更改它;不使用 CustomBinding?

【问题讨论】:

  • wsHttpBinding 上 maxRetryCount 的默认值为 8 - 当然,它只有在启用可靠会话的情况下才有效。这就是可以在客户端和服务器上缓冲的消息数量——乘以你允许的最大消息大小,你就会知道“可靠性”缓冲区会有多大。你不想让它太大。
  • 据我所知,除了使用自定义绑定(在您的 app.config/web.config 中或通过代码配置)将该值设置为其他值之外,别无他法8.
  • 好的。感谢您指出这一点。

标签: wcf wshttpbinding ws-reliablemessaging


【解决方案1】:

您不能在标准wsHttpBinding 配置上设置maxRetryCount。为了设置该值,您需要创建一个单独的自定义绑定,然后从您的服务或客户端配置中引用它:

  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="wsCustomBinding">
          <reliableSession maxRetryCount="15"/>
          <textMessageEncoding/>
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    <services>
      <service name="MyService">
        <endpoint address="http://localhost:7878/MyServoce"
                  binding="customBinding"
                  bindingConfiguration="wsCustomBinding"
                  contract="IMyService" />
      </service>
    </services>
  </system.serviceModel>

定义自定义绑定并不难 - 但您需要确保以正确的顺序指定构成绑定的元素 - 请参阅 MSDN docs on custom bindings 以获取参考。

如果您想在服务器和客户端之间共享自定义绑定配置,您还可以将该 &lt;bindings&gt; 部分放入单独的 bindings.config 文件中,然后从您的 web.config/app.config 中引用该外部文件:

  <system.serviceModel>
    <bindings configSource="bindings.config">

Visual Studio 会抱怨这一点并显示红色波浪下划线 - 但相信我 - 该技术有效,我每天都在生产中使用它(描述配置内容的 Visual Studio XML 架构并不完整和准确)。

马克

【讨论】:

  • 是的,我知道 customBinding 解决方法。您是否知道 wsHttpBinding 上的重试计数值是多少,或者是否为 ws 绑定禁用了重试?
  • @marc_s 什么会导致重试?超时 ?服务器异常?硬件错误? (在目标服务上...)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-20
  • 2011-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多