title: WCF multiple endpoints
body: <p>I would to expose my WCF service on multiple endpoints. 
  I don't understand why this error, because each endpoint has unique address.</p>
  
  <p>Do I have to expose mex endpoint for each separate endpoint?</p>
  
  <p>Error is:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: A binding instance has already been associated to listen URI '<a href="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" rel="nofollow noreferrer">http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/</a>'. If two endpoints want to share the same ListenUri, they must also share the same binding object instance. The two conflicting endpoints were either specified in AddServiceEndpoint() calls, in a config file, or a combination of AddServiceEndpoint() and config. 
       at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
       at System.ServiceModel.ServiceHostBase.InitializeRuntime()
       at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)</p>
  </blockquote>
  
  <pre><code>    using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  
  namespace WcfServiceLibrary1
  {
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
      [OperationContract]
      string GetData(int value);
  
      [OperationContract]
      CompositeType GetDataUsingDataContract(CompositeType composite);
  
      // TODO: Add your service operations here
    }
  
    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    // You can add XSD files into the project. After building the project, you can directly use the data types defined there, with the namespace "WcfServiceLibrary1.ContractType".
    [DataContract]
    public class CompositeType
    {
      bool boolValue = true;
      string stringValue = "Hello ";
  
      [DataMember]
      public bool BoolValue
      {
        get { return boolValue; }
        set { boolValue = value; }
      }
  
      [DataMember]
      public string StringValue
      {
        get { return stringValue; }
        set { stringValue = value; }
      }
    }
  }
  
  
  
  
      namespace WcfServiceLibrary1
  {
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class Service1 : IService1
    {
      public string GetData(int value)
      {
        return string.Format("You entered: {0}", value);
      }
  
      public CompositeType GetDataUsingDataContract(CompositeType composite)
      {
        if (composite == null)
        {
          throw new ArgumentNullException("composite");
        }
        if (composite.BoolValue)
        {
          composite.StringValue += "Suffix";
        }
        return composite;
      }
    }
  }
  </code></pre>
  
  <p>Configuration file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
  
    &lt;appSettings&gt;
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" /&gt;
    &lt;/system.web&gt;
    &lt;!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="WcfServiceLibrary1.Service1"&gt;        
          &lt;!-- Service Endpoints --&gt;
          &lt;!-- Unless fully qualified, address is relative to base address supplied above --&gt;
          &lt;endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
                    binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1" name="first" /&gt;
  
          &lt;endpoint address="http://localhost:8734/Design_Time_Addresses/WcfServiceLibrary1/Service2/"
                    binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1" name="second" /&gt;
  
          &lt;endpoint address="http://localhost:8735/Design_Time_Addresses/WcfServiceLibrary1/Service3/"
                    binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1" name="third" /&gt;
  
  
  
          &lt;!-- Metadata Endpoints --&gt;
          &lt;!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --&gt; 
          &lt;!-- This endpoint does not use a secure binding and should be secured or removed before deployment --&gt;
          &lt;endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
          &lt;endpoint address="http://localhost:8734/Design_Time_Addresses/WcfServiceLibrary1/Service2/" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
          &lt;endpoint address="http://localhost:8735/Design_Time_Addresses/WcfServiceLibrary1/Service3/" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;!-- To avoid disclosing metadata information, 
            set the values below to false before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, 
            set the value below to true.  Set to false before deployment 
            to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="False" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
  
  &lt;/configuration&gt;
  </code></pre>