我使用WCF Discovery UDPEndpoint进行了测试,它可以在我自己的计算机上运行,但如果我将它发布到IIS,然后从其他计算机调用它,则无法找到它 .
我用IP设置了地址 .
服务
using (ServiceHost host = new ServiceHost(typeof(DiscoveryProxy), new Uri("http://xx.xxxx.xxx.xxx:8080/DiscoveryProxy")))
{
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
ServiceEndpoint sep= host.AddServiceEndpoint(typeof(IDiscoveryProxy),new BasicHttpBinding(),"");
sep.ListenUri = new Uri("http://xx.xxxx.xxx.xxx:8080/DiscoveryProxy/via");
ServiceDiscoveryBehavior sdb = new ServiceDiscoveryBehavior();
sdb.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());
host.Description.Behaviors.Add(sdb);
host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
host.Open();
Console.WriteLine("service is open");
Console.ReadLine();
host.Close();
}
在客户端正确添加服务引用,我可以从IE浏览服务 . 但它无法通过UDP发现 .
客户
DiscoveryClient client = new DiscoveryClient(new UdpDiscoveryEndpoint());
FindResponse response = client.Find(new FindCriteria(typeof(myDiscoveryProxy)));
if (response.Endpoints.Count > 0)
{
EndpointAddress address = response.Endpoints[0].Address;
Console.WriteLine("service address is " + address);
ServiceReference2.myDiscoveryProxyClient service = new ServiceReference2.myDiscoveryProxyClient(new BasicHttpBinding(), address);
service.getString("discovery proxy");
}
我在客户端和服务中都打开了UDP端口 . 有没有办法解决这个问题?
1 回答
看来我已经达到了我的要求 . 我在服务端配置防火墙 . 具有高级安全性的Windows防火墙 - >入站规则 - >新规则 - >端口 - > UDP->所有本地端口 - >允许此规则的连接 - >域,专用,公共 - >名称 . 但我不知道为什么我需要这个,我的应用程序已经在防火墙中配置了Udp协议 .