WCF discovery does not work between two computers on the same subnet when the firewall is turned off

This simple WCF discovery example runs on the same machine, but when the client and server are running on separate computers on the same subnet without a firewall, this does not work. What am I missing?

using System; using System.Linq; using System.Net; using System.Net.Sockets; using System.ServiceModel; using System.ServiceModel.Discovery; namespace WCFDiscovery { class Program { static void Main(string[] args) { try { if (args.Length > 0) StartClient(); else StartServer(); } catch (Exception ex) { Console.WriteLine(ex); } finally { Console.WriteLine("press enter to quit..."); Console.ReadLine(); } } private static void StartServer() { var ipAddress = Dns.GetHostAddresses(Dns.GetHostName()).First(ip => ip.AddressFamily == AddressFamily.InterNetwork); var address = new Uri(string.Format("net.tcp://{0}:3702", ipAddress)); var host = new ServiceHost(typeof(Service), address); host.AddServiceEndpoint(typeof(IService), new NetTcpBinding(), address); host.Description.Behaviors.Add(new ServiceDiscoveryBehavior()); host.AddServiceEndpoint(new UdpDiscoveryEndpoint()); host.Open(); Console.WriteLine("Started on {0}", address); } private static void StartClient() { var dc = new DiscoveryClient(new UdpDiscoveryEndpoint()); Console.WriteLine("Searching for service..."); var findResponse = dc.Find(new FindCriteria(typeof(IService))); var response = ChannelFactory<IService>.CreateChannel(new NetTcpBinding(), findResponse.Endpoints[0].Address).Add(1, 2); Console.WriteLine("Service response: {0}", response); } } [ServiceContract] interface IService { [OperationContract] int Add(int x, int y); } class Service : IService { public int Add(int x, int y) { return x + y; } } } 
+6
source share
2 answers

I ran your code on two different computers (laptop (Win7) and Tower PC (Win8), NET FW 4.5, the same WiFi network) and received the following exception:

 A remote side security requirement was not fulfilled during authentication. Try increasing the ProtectionLevel and/or ImpersonationLevel. 

This is due to the fact that the security service is not specified, the endpoint was found. So the guys in the other answers are right - this is a network problem that cannot be fixed by fixing the code. I would add that another possible source of the problem could be a network switch that does not allow UDP broadcasts.

+2
source

To be clear, is Windows Firewall also disabled?

Also make sure that you bind your server to the address that another computer uses to communicate with it.

Local or 127.0.0.1, most likely, will not pick up a connection with its external (to the host) addressable IP address, to which multicast discovery packets will arrive.

MSDN Instructions for Disabling Windows Firewall

+1
source

All Articles