title: How to configure WCF binding programmatically?
body: <p>I need to implement following using code:</p>
  
  <pre><code>&lt;basicHttpBinding&gt;
  
          &lt;binding name="NewBinding"&gt;
  
            &lt;security mode="TransportCredentialOnly"&gt;
  
              &lt;transport clientCredentialType="Basic" /&gt;
  
            &lt;/security&gt;
  
          &lt;/binding&gt;
  
        &lt;/basicHttpBinding&gt;
  </code></pre>
  
  <p>Is there any samples available? I'm working on WCF REST service and register routes manually. Placing this config into configuration doesn't work. I'd like to get it setup programmatically if possible. Also, at what point in code I should do it?</p>
  
  <p>EDIT: </p>
  
  <p>My service Routed in Global.asax like so:</p>
  
  <pre><code>foreach (var account in cmc.Accounts.Where(aa =&gt; aa.IsActive).ToList())
                  {
                      RouteTable.Routes.Add(
                          new ServiceRoute(
                              account.AccountId + "/mobile", new MyServiceHostFactory(), typeof(MobileService)));
                  }
  </code></pre>
  
  <p>And I have my own ServiceHost</p>
  
  <pre><code>public class MyServiceHost : WebServiceHost
      {
          private readonly Type _serviceType;
          private readonly CompositionContainer _container;
  
          public MyServiceHost(Type serviceType, CompositionContainer container, params Uri[] baseAddresses)
              : base(serviceType, baseAddresses)
          {
              _serviceType = serviceType;
              _container = container;
          }
  
          protected override void OnOpening()
          {
              if (Description.Behaviors.Find&lt;MyServiceBehavior&gt;() == null)
              {
                  Description.Behaviors.Add(new MyServiceBehavior(_serviceType, _container));
              }
  
              base.OnOpening();
          }
      }
  </code></pre>