title: Programmatically access multiple endpoints in a WCF service
body: <p>I am getting an error while accessing the second endpoint in a self hosted WCF service. Below is my code:</p>
  
  <pre><code>Uri HttpUri = new Uri("http://localhost:8092/MyService/HttpService");
  ServiceHost host = new ServiceHost(typeof(PollService),HttpUri);
  host.AddServiceEndpoint(typeof(ISub), myBinding, ""); //My binding is my custom binding and this end point is working fine.
  
  host.AddServiceEndpoint(typeof(IFocus), 
      new BasicHttpBinding(),
      new uri("http://localhost:8092/MyService/Focusservice"));
  
  ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
  smb.HttpGetEnabled = true;
  host.Description.Behaviors.Add(smb);
  host.Open();
  </code></pre>
  
  <p>From the code I can access my custom binding url:</p>
  
  <pre><code>http://localhost:8092/MyService/HttpService`
  </code></pre>
  
  <p>But I'm not able to access:</p>
  
  <pre><code> http://localhost:8092/MyService/Focusservice
  </code></pre>
  
  <p>When accessing it in the WCF test client it throws error as follows: </p>
  
  <blockquote>
    <p>Error: Cannot obtain Metadata from <code>http://localhost:8092/MyService/basicbinding</code><br>
    If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at <a href="http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata" rel="nofollow">link</a></p>
    
    <p>Exchange Error. URI: <code>http://localhost:8092/MyService/basicbinding</code> Metadata contains a reference that cannot be resolved: <code>http://localhost:8092/MyService/basicbinding</code>.  </p>
    
    <p>Content Type application/soap+xml; charset=utf-8 was not supported by service <code>http://localhost:8092/MyService/basicbinding</code>.  </p>
    
    <p>The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'. </p>
    
    <p>HTTP GET Error. URI: <code>http://localhost:8092/MyService/basicbinding</code> There was an error downloading <code>'http://localhost:8092/MyService/basicbinding'</code>. The request failed with HTTP status 400: Bad Request.</p>
  </blockquote>