title: WCF: Net.TCP multiple bindings, same port, different IP Addresses
body: <p>I've run into a problem. I'm a little new at WCF so any help would be greatly appreaciated.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public static void StartHosts()
      {
          try
          {
              // Create a new host
              ServiceHost host = new ServiceHost(typeof(ServerTasks));
  
              List&lt;IPAddress&gt; ips = new List&lt;IPAddress&gt;(Dns.GetHostAddresses(Dns.GetHostName()));
              if (IPAddress.Loopback != null)
                  ips.Add(IPAddress.Loopback);
  
              ips.RemoveAll(i =&gt; i.AddressFamily != AddressFamily.InterNetwork);
  
              foreach (var ip in ips)
              {
                  string uri = string.Empty;
  
                  // Formulate the uri for this host
                  uri = string.Format(
                      "net.tcp://{0}:{1}/ServerTasks",
                      ip.ToString(),
                      ServerSettings.Instance.TCPListeningPort
                  );
  
  
                  // Add the endpoint binding
                  host.AddServiceEndpoint(
                      typeof(ServerTasks),
                      new NetTcpBinding(SecurityMode.Transport) { TransferMode = TransferMode.Streamed },
                      uri
                  );
  
              }
  
  
  
              // Add the meta data publishing
              var smb = host.Description.Behaviors.Find&lt;ServiceMetadataBehavior&gt;();
              if (smb == null)
                  smb = new ServiceMetadataBehavior();
  
              smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
              host.Description.Behaviors.Add(smb);
  
              host.AddServiceEndpoint(
                  ServiceMetadataBehavior.MexContractName,
                  MetadataExchangeBindings.CreateMexTcpBinding(),
                  "net.tcp://localhost/ServerTasks/mex"
              );
  
              // Run the host
              host.Open();
          }
          catch (Exception exc)
          {
              DebugLogger.WriteException(exc);
          }
      }
  </code></pre>
  
  <p>An exception is thrown on the line: 'host.Open();'</p>
  
  <p>The exception is:</p>
  
  <p><strong><em>System.InvalidOperationException</strong>
  A registration already exists for URI 'net.tcp://192.168.1.45:4329/ServerTasks'.</em></p>
  
  <p>What I'm trying to do is bind to all the network addresses on the machine so that the client applications can reach the service from whatever network they see it on. When I run this code it finds and attempts to set up a binding for about 5 different IPs, including 127.0.0.1. </p>
  
  <p>192.168.1.45 is the second IP that it attempts to bind to. At the point that it throws the exception I can see (using netstat) that the program has bound to the first IP in the list on port 4329. There isn't anything bound to port 4329 on the address mentioned in the exception.</p>
  
  <p>Sorry there's not a lot of details, I wanted to give a concise post. If anyone needs any more info I'll be happy to supply it.</p>
  
  <p>Note: I've tried setting PortSharingEnabled to true for the NetTcpBinding that gets created inside the foreach loop, but I still experienced the same error.</p>
  
  <p>Any help or advise would be greatly appreaciated!</p>
  
  <p>Thanks</p>