1

我用 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 端口。有没有办法解决这个问题?

4

1 回答 1

0

看来我已经达到了我的要求。我在我的服务端配置防火墙。Windows 防火墙高级安全->入站规则->新规则->端口->UDP->所有本地端口->允许连接->域、私有、公共->此规则的名称。但我不确定为什么需要这个,我的应用程序已经在防火墙中配置了 Udp 协议。

于 2016-06-28T12:28:31.227 回答