WSHttp 绑定和 ReliableSession / MaxRetryCount

发布于 2024-08-16 04:26:12 字数 365 浏览 15 评论 0原文

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

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

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

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

When using a WSHttpBinding in WCF with reliableSessions enabled, my service reference updates itself to:

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

I cannot add the maxRetryCount attribute to the reliableSession as long as the binding is configured as a WSHttpBinding.

Now my question: what is the value of maxRetryCount when using a WSHttpBinding, and is there any way to change this in config; without the use of a CustomBinding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2024-08-23 04:26:12

您无法在标准 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 文档以获取参考。

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

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

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

马克

You cannot set the maxRetryCount on a standard wsHttpBinding configuration. In order to set that value, you need to create a separate custom binding and then reference that from your service or client config:

  <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>

Defining a custom binding isn't hard - but you need to make sure you specify the elements that make up the binding in the right order - see the MSDN docs on custom bindings for a reference.

If you want to share the custom binding configuration between server and client, you could also put that <bindings> section into a separate bindings.config file, and then reference that external file from your web.config/app.config:

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

Visual Studio will complain about this and show red squiggly underlines - but trust me - the technique works, I use it in production every day (the Visual Studio XML schema describing the config stuff isn't complete and accurate).

Marc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文