title: Moving service configuration from the config to code
body: <p>I have the following configuration in my app.config:</p>
  
  <pre><code>&lt;bindings&gt;
    &lt;customBinding&gt;
      &lt;binding name="myBinding"&gt;
        &lt;textMessageEncoding messageVersion="Soap12"/&gt;
        &lt;httpTransport/&gt;
      &lt;/binding&gt;
    &lt;/customBinding&gt;
    &lt;wsHttpBinding&gt;
      &lt;binding name="myBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8"&gt;
        &lt;security mode="Transport"&gt;
          &lt;transport clientCredentialType="Windows"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/wsHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;client&gt;
    &lt;endpoint address="/../" binding="wsHttpBinding" bindingConfiguration="myBinding" contract="myContract" name="myName"/&gt;
  &lt;/client&gt;
  </code></pre>
  
  <p>Using this configuration the service works as expected. </p>
  
  <p>For several reasons i can't use the app.config file in the production environment, so i want to define the bindings in c# instead. I did the following:</p>
  
  <pre><code>        var binding = new BasicHttpBinding();
          var address = new EndpointAddress(url);
  
          binding.Security = new BasicHttpSecurity() { Mode = BasicHttpSecurityMode.Transport };
          binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
  
          var client = new MyClient(binding, address);
  </code></pre>
  
  <p>This works for the first part, but then fails on using an incorrect message version. I can see this is defined in the custombinding, but i'm not sure how to translate this binding to my code. I did try quite a lot, but with no result so far. </p>
  
  <p>Does anyone know how to do this? </p>