WSHttp绑定和ReliableSession / MaxRetryCount

时间:2009-12-28 10:13:30

标签: wcf wshttpbinding ws-reliablemessaging

在WCF中使用WSHttpBinding且启用了reliableSessions时,我的服务引用将自身更新为:

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

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

现在我的问题是:使用WSHttpBinding时maxRetryCount的值是多少,有没有办法在config中更改它;不使用CustomBinding?

1 个答案:

答案 0 :(得分:8)

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

  <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以获取参考。

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

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

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

马克