代码之家  ›  专栏  ›  技术社区  ›  Jan Jongboom

wshttp绑定和可靠会话/maxretrycount

  •  3
  • Jan Jongboom  · 技术社区  · 15 年前

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

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

    我不能添加 maxRetryCount 属性设置为ReliableSession,只要绑定配置为wshttpbinding。

    现在我的问题是:什么是价值 最大次数计数 当使用wshttpbinding时,是否有任何方法可以在config中更改它;而不使用custombinding?

    1 回复  |  直到 15 年前
        1
  •  8
  •   marc_s    15 年前

    您不能设置 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模式并不完整和准确)。

    马克

    推荐文章