title: Mono and WCF Net.Tcp Binding on all IP Addresses
body: <p>As mentioned in <a href="http://mel-green.com/2009/04/wcf-nettcp-binding-on-all-ip-addresses/" rel="nofollow noreferrer">this</a> article, in .net it's possible to bind a web service to all ip addresses using the "address" 0. However, this doesn't seem to work with mono (version 2.10.8.1).    </p>
  
  <p>Here is my example code:</p>
  
  <p>Client:  </p>
  
  <pre><code>string ipAddressOfTheService = "192.168.0.23";
  EndpointAddress address = new EndpointAddress(string.Format("net.tcp://{0}:8081/myService", ipAddressOfTheService));
  NetTcpBinding binding = new NetTcpBinding();
  ServiceProxy proxy = new ServiceProxy(binding, address);
  if(proxy.CheckConnection())
  {
      MessageBox.Show("Service is available");
  }
  else
  {
      MessageBox.Show("Service is not available");
  }
  </code></pre>
  
  <p>ServiceProxy:  </p>
  
  <pre><code>public class ServiceProxy : ClientBase&lt;IMyService&gt;, IMyService
  {
      public ServiceProxy(Binding binding, EndpointAddress address)
          : base(binding, address)
      {
      }
  
      public bool CheckConnection()
      {
          bool isConnected = false;
          try
          {
              isConnected = Channel.CheckConnection();
          }
          catch (Exception)
          {
          }
          return isConnected;
      }
  }
  </code></pre>
  
  <p>IMyService:  </p>
  
  <pre><code>[ServiceContract]
  public interface IMyService
  {
      [OperationContract]
      bool CheckConnection();
  }
  </code></pre>
  
  <p>MyService:  </p>
  
  <pre><code>class MyService : IMyService
  {
      public bool CheckConnection()
      {
          Console.WriteLine("Check requested!");
          return true;
      }
  }
  </code></pre>
  
  <p>ServiceHost:  </p>
  
  <pre><code>class MyServiceHost
  {
      static void Main(string[] args)
      {
          Uri baseAddress = new Uri(string.Format("net.tcp://0:8081/myService");
          using (ServiceHost host = new ServiceHost(typeof(MonitoringService), baseAddress))
          {
              NetTcpBinding binding = new NetTcpBinding();
              binding.Security.Mode = SecurityMode.None;
  
              host.AddServiceEndpoint(typeof(IMyService), binding, baseAddress);
              host.Open();
              Console.WriteLine("The service is ready at {0}", baseAddress);
              Console.WriteLine("Press &lt;Enter&gt; to stop the service.");
              Console.ReadLine();
              host.Close();
          }
      }
  }
  </code></pre>
  
  <p>If I run this (service and client) on a windows PC using .net all works fine.<br>
  On my Linux machine (Raspberry Pi, Debian soft-float) the service start without any problems, however the client cant connect.<br>
  If I host the service with its ip address instead of the "0" address everything works correct.</p>
  
  <p>Is this just another bug in mono or do i have to bind to any other ip address instead of the 0?
  If it's a bug in mono, are there any workarounds?   </p>
  
  <p><em>(By the way, I'm still searching for an workaround for the port sharing problems with mono/net.tcp, if anyone could help here -> <a href="https://stackoverflow.com/questions/15948639/net-tcp-port-sharing-and-mono">net.tcp port sharing and mono</a>)</em></p>