WSHttp binding and ReliableSession / MaxRetryCount

帅比萌擦擦* 提交于 2019-11-27 06:31:27

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/1968799/wshttp-binding-and-reliablesession-maxretrycount

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!