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; } } }
Robin source share