Mono and WCF Net.Tcp binding to all IP addresses

As mentioned in this article, in .net you can associate a web service with all IP addresses using the "address" 0. However, this does not seem to work with mono (version 2.10.8.1).

Here is my sample code:

Customer:

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"); } 

ServiceProxy:

 public class ServiceProxy : ClientBase<IMyService>, IMyService { public ServiceProxy(Binding binding, EndpointAddress address) : base(binding, address) { } public bool CheckConnection() { bool isConnected = false; try { isConnected = Channel.CheckConnection(); } catch (Exception) { } return isConnected; } } 

IMyService:

 [ServiceContract] public interface IMyService { [OperationContract] bool CheckConnection(); } 

MyService:

 class MyService : IMyService { public bool CheckConnection() { Console.WriteLine("Check requested!"); return true; } } 

ServiceHost:

 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 <Enter> to stop the service."); Console.ReadLine(); host.Close(); } } } 

If I run this (service and client) on a Windows PC using .net, everything works fine.
On my Linux machine (Raspberry Pi, Debian soft-float) the service starts without any problems, however, the client cannot connect.
If I host a service with its IP address instead of the "0" address, everything works correctly.

Is this just another mistake in mono or do I need to bind to any other ip address instead of 0? If this is a bug in mono, are there any workarounds?

(By the way, I'm still looking for a workaround for port-sharing issues with mono / net.tcp, if someone can help here - > net.tcp and mono file sharing )

+4
source share
2 answers

Try using + or * instead of 0 to bind to all addresses.

Edit: or try 0.0.0.0

Edit2: Looks like a bug in Mono. You can report this https://bugzilla.xamarin.com/index.cgi

0
source

I had a similar problem in Ubuntu Server 16.04 LTS and the Mono JIT compiler version 5.0.1.1 (2017-02 / 5077205 Thu 25 May 09:19:18 UTC 2017).

I resolved it by adding the following line to /etc/hosts :

0.0.0.0 IP4Any

Next, bind the service to IP4Any .

0
source

All Articles