3

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

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

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

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

4

1 回答 1

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

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

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

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

马克

于 2009-12-28T10:39:48.027 回答