title: WCF Service listening to multiple ports
body: <p>I need to install a WCF service on a single server but I need to listen to multiple ports (due to various issues with machines running the client).  It's not clear to me if this can be done with one <code>ServiceHost</code> and: one "class dervied from"(CDF) <code>ServiceBase</code> with two <code>endpoints</code>, or if I need two CDF <code>ServiceBase</code>s each with a single <code>endpoint</code>.  Here is the relevant code in relevant files:</p>
  
  <p>Program.cs</p>
  
  <pre><code>static class Program
  {
      static void Main()
      {
          ServiceBase[] ServicesToRun;
          ServicesToRun = new ServiceBase[]
          {
              new Service1()
          };
          ServiceBase.Run(ServicesToRun);
      }
  }
  </code></pre>
  
  <p>Service1.cs</p>
  
  <pre><code>public partial class Service1 : ServiceBase
  {
      private wcfServer _server;
      ServiceHost serviceHost;
  
      public Service1()
      {
          InitializeComponent();
      }
  
      protected override void OnStart(String[] args)
      {
          _server = new wcfServer();
          serviceHost = new ServiceHost(_server);
          serviceHost.Open();
      }
  
      protected override void OnStop()
      {
          if (serviceHost != null)
              serviceHost.Close();
      }
  }
  </code></pre>
  
  <p>wcfServer.cs</p>
  
  <pre><code>[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
      ConcurrencyMode=ConcurrencyMode.Multiple)]
  public class wcfServer : IwcfServer { /* ... */ }
  </code></pre>
  
  <p>app.config</p>
  
  <pre><code>&lt;services&gt;
      &lt;service name="MyService.wcfServer"&gt;
          &lt;endpoint address=""
              bindingConfiguration="BigDataBinding"
              binding="basicHttpBinding"
              contract="DataBackups.IwcfServer"&gt;
              &lt;identity&gt;
                  &lt;dns value="localhost" /&gt;
              &lt;/identity&gt;
          &lt;/endpoint&gt;
  
          &lt;endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" /&gt;
  
          &lt;host&gt;
              &lt;baseAddresses&gt;
                  &lt;add baseAddress="http://localhost/DataBackups/wcfServer/" /&gt;
              &lt;/baseAddresses&gt;
          &lt;/host&gt;
      &lt;/service&gt;
  &lt;/services&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>I should note that</p>
  
  <ol>
  <li>the current "solution" to this issue is to alter the installer to allow us to install the service on the server <em>twice</em>.</li>
  <li>the purpose of the service is to handle multiple concurrent requests that, in part, stream big data (in case this is relevant).</li>
  </ol>
  
  <p>Can someone provide an example of how to accomplish this?  </p>
  
  <p>Also, I do not understand how <code>&lt;service&gt;</code> configurations in <code>app.config</code> relate to CDF <code>ServiceBase</code> instances created programmatically.  In the current setup, there is only a single <code>Service1</code> instance and a single configuration in <code>app.config</code>, so I imagine they "line up."  But, what if I there are multiple <code>Service1</code> instances (which I might need)?  How do I "choose" which service I am configuring?</p>