title: WCF Custom Binding - The Scheme cannot be computed because this CustomBinding lacks a TransportBindingElement
body: <p>I am using custom binding and getting following error :</p>
  
  <p><strong>The Scheme cannot be computed for this binding because this CustomBinding lacks a TransportBindingElement.  Every binding must have at least one binding element that derives from TransportBindingElement.</strong></p>
  
  <p>My Custom Binding Code as follows </p>
  
  <pre><code>public class MyCustomBinding : Binding
      {
          private HttpTransportBindingElement transport;
          private BinaryMessageEncodingBindingElement encoding;
  
          public MyCustomBinding()
              : base()
          {
              this.InitializeValue();
          }
          public override BindingElementCollection CreateBindingElements()
          {
              BindingElementCollection elements = new BindingElementCollection();
              elements.Add(this.encoding);
              elements.Add(this.transport);
              return elements;
          }
          public override string Scheme
          {
              get { return this.transport.Scheme; }
          }
          private void InitializeValue()
          {
              this.transport = new HttpTransportBindingElement();
              this.encoding = new BinaryMessageEncodingBindingElement();
          }
      }
  
      public class MyCustomBindingCollectionElement : BindingCollectionElement
      {
          // type of custom binding class
          public override Type BindingType
          {
              get { return typeof(MyCustomBinding); }
          }
  
         //  override ConfiguredBindings
          public override ReadOnlyCollection&lt;IBindingConfigurationElement&gt; ConfiguredBindings
          {
              get
              {
                  return new ReadOnlyCollection&lt;IBindingConfigurationElement&gt;(
                  new List&lt;IBindingConfigurationElement&gt;());
              }
          }
  
          // return Binding class object
          protected override Binding GetDefault()
          {
              return new MyCustomBinding();
          }
  
          public override bool ContainsKey(string name) {
  
              return true;
          }
  
          protected override bool TryAdd(string name, Binding binding, Configuration config)
          {
              return true;
          }
      }
  </code></pre>
  
  <p>Web.config code is as follows:</p>
  
  <pre><code>&lt;extensions&gt;
        &lt;bindingExtensions&gt;
          &lt;!--&lt;add name="ProxyElement" type="ADHA.Model.HttpTransportBindingElementProxy, ADHA"/&gt;--&gt;
        &lt;add name="MyCustomBinding" type="ADHA.Model.MyCustomBindingCollectionElement,ADHA,
                 Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt;
        &lt;/bindingExtensions&gt;
      &lt;/extensions&gt;
  
  &lt;service&gt;      
      &lt;services&gt;
   &lt;endpoint address="" binding="customBinding" bindingConfiguration="MyCustomBinding" contract="ADHA.IADHAService"&gt;
              &lt;/endpoint&gt;
           &lt;endpoint address="mex" binding="customBinding" contract="IMetadataExchange" /&gt;
  
        &lt;/service&gt;      
      &lt;/services&gt;
  
  &lt;bindings&gt;
     &lt;customBinding&gt;
          &lt;binding name="MyCustomBinding"&gt;
            &lt;binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                                   maxSessionSize="2048"&gt;
              &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                       maxBytesPerRead="4096" maxNameTableCharCount="16384"/&gt;
            &lt;/binaryMessageEncoding&gt;        
            &lt;textMessageEncoding
              messageVersion="Soap11WSAddressingAugust2004"/&gt;
           &lt;httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
                           maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
           bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
          keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
          realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true"/&gt;
          &lt;/binding&gt;
  
        &lt;/customBinding&gt;
  
      &lt;/bindings&gt;
  </code></pre>
  
  <p>Someone please tell me whats wrong with my code?</p>