wcfwshttpbindingws-reliablemessaging

WSHttp binding and ReliableSession / MaxRetryCount


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?


Solution

  • 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