Changing bindingConfiguration's dynamically

I have a new requirement that communications between apps on Server A communicate over https to web services hosted on Server B. This will happen in our QA and Prod environments. However, it will (likely) not happen in our Dev environment, and Octopus Deploy is handling all 3 environments.

AFAIK, in .Net, the bindings must match between the client and service. For example, on my client app I will have this under the <system.serviceModel> in the *.config:

    <bindings>
      <basicHttpBinding>
        <binding name="largeMessageBinding" maxReceivedMessageSize="65536000">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://myurl.com/MyService.svc" behaviorConfiguration="largeMessageBehavior" binding="basicHttpBinding" 
                bindingConfiguration="largeMessageBinding" contract="MyNameSpace.IMyService" name="MyService" />
      </endpoint>
    </client>

and this in the web.config of the web service:

    <services>
      <service name="MyNamespace.MyService" behaviorConfiguration="entryBehavior">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="largeMessageBinding" contract="MyNamespace.IMyService" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="largeMessageBinding" maxReceivedMessageSize="65536000">
          <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>

Both client and web service are deployed with Octopus.

The question is: how do I switch between basicHttpBinding/largeMessageBinding (currently with security mode Transport), and another binding (which would presumably be security mode None in dev)? The core issue is that the Octopus-deployed web service is securely hosted in QA and Prod, but not dev. And then the Octopus-deployed end client must match the binding.

All I can think of is a custom Powershell script or step that will take some arguments and dynamically change the bindingConfiguration’s on the client and service. And both bindings would have to already exist in the *.config’s. e.g.:

    <bindings>
      <basicHttpBinding>
        <binding name="httpsMessageBinding" maxReceivedMessageSize="65536000">
          <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
          <security mode="Transport" />
        </binding>
        <binding name="httpMessageBinding" maxReceivedMessageSize="65536000">
          <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>

There are multiple endpoints, btw.

Thoughts?

Thx
Tom

Hi Tom,

Thanks for getting in touch! You could use a config transformation to achieve what you are looking for. Both Server and Client would have to use the same config transformation if you want to keep them in sync.

Please let me know how you go.

Regards,

Pawel