यह सरल WCF खोज उदाहरण एक मशीन पर काम करता है, लेकिन बंद कर दिया जब क्लाइंट और सर्वर कोई फ़ायरवॉल के साथ एक ही सबनेट में अलग मशीनों पर चल रहे हैं, यह काम नहीं करता है। मैं क्या खो रहा हूँ?WCF खोज एक ही सबनेट पर दो कंप्यूटरों के बीच काम नहीं करता है के साथ फ़ायरवॉल
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; } }
}
_ "जब क्लाइंट और सर्वर अलग मशीनों पर चल रहे हैं" _ - आप तो एक दूसरे पते का उपयोग करते हैं? इसके अलावा: _ "यह काम नहीं करता है" _ अपवाद नहीं है। सटीक संदेश दिखाएं। – CodeCaster
सर्वर पोर्ट 8000 पर सुनता द्वारा "काम नहीं करता है" मेरा मतलब है कि "dc.Find (...)" रिटर्न अंतिमबिंदुओं शून्य तो यह कोड "अंतिम बिंदु [0]" एक ArgumentOutOfRangeException – Robin
फेंकता है यह अगर कोई फर्क पड़ता है आप अपने सर्वर के आईपी पते पर "लोकलहोस्ट" बदलते हैं कि आपका ग्राहक कनेक्ट हो जाएगा? – sclarson