Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 其他网络上的WCF UDP发现_C#_Wcf_Service Discovery_Ws Discovery - Fatal编程技术网

C# 其他网络上的WCF UDP发现

C# 其他网络上的WCF UDP发现,c#,wcf,service-discovery,ws-discovery,C#,Wcf,Service Discovery,Ws Discovery,我们公司有两个不同的网络,17和18 170.17.xxx.xxx 170.18.xxx.xxx 在17网络上,有一个WCF服务正在运行,可以发现。 这由以下代码配置: host.AddDefaultEndpoints(); host.AddServiceEndpoint(new UdpDiscoveryEndpoint()); EndpointDiscoveryBehavior behavior = new EndpointDiscoveryBehavior(); behavior.Sc

我们公司有两个不同的网络,17和18

  • 170.17.xxx.xxx
  • 170.18.xxx.xxx
在17网络上,有一个WCF服务正在运行,可以发现。 这由以下代码配置:

host.AddDefaultEndpoints();
host.AddServiceEndpoint(new UdpDiscoveryEndpoint());

EndpointDiscoveryBehavior behavior = new EndpointDiscoveryBehavior();
behavior.Scopes.Add(scope);

foreach(ServiceEndpoint endpoint in host.Description.Endpoints)
{
    if(endpoint.IsSystemEndpoint || endpoint is DiscoveryEndpoint    || 
       endpoint is AnnouncementEndpoint || endpoint is ServiceMetadataEndpoint)
        continue;

    endpoint.Behaviors.Add(behavior);
}
具有作用域的行为将添加到所有非系统端点,并且可以通过网络发送udp数据包(UdpDiscoveryEndpoint的默认实例)来发现该行为

DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

FindCriteria criteria = new FindCriteria(typeof(T));
criteria.Scopes.Add(scope);

FindResponse discovered = discoveryClient.Find(criteria);
discoveryClient.Close();
客户端通过构造一个具有默认UdpDiscoveryEndpoint的DiscoveryClient来发现服务

DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

FindCriteria criteria = new FindCriteria(typeof(T));
criteria.Scopes.Add(scope);

FindResponse discovered = discoveryClient.Find(criteria);
discoveryClient.Close();
当客户机和服务在同一网络上运行时,这种方法可以很好地工作。 但我希望有一个客户机运行在18个网络上,能够找到17个网络上的服务

那么,是否可以使用DiscoveryClient和UdpDiscoveryEndpoint在其他网络上发现服务

编辑


或者这可能是防火墙问题吗?

这不是防火墙问题,而是WS-Discovery的正常行为。WS-Discovery使用SOAP over UDP发送到多播IP组(239.255.255.250)。多播数据包通常不会被路由,而是停留在本地网络的限制范围内。因此,如果没有外部帮助,DiscoveryClient无法在其他网络上发现服务

您有两个选择:

  • 配置路由器以在彼此之间传递多播IP流量。虽然很容易实现,但可能会不必要地加载网络间链接,也可能需要ISP的帮助,或者您可能需要某种类型的隧道
  • 在可发现服务所在的网络上设置所谓的“发现代理”。发现代理基本上在本地执行发现,然后使用HTTP将发现结果传递到其他网络。由于发现代理具有相同的SOAP WSDL,现有WS-Discovery客户端可以使用它,而无需在internet上进行任何更改

  • @Vladimir Bashkirtsev,我需要在包含两个子网的小型企业网络上实现WS-Discovery“发现代理”。经过大量的研究,似乎没有一个“随时可用”的发现代理,我可以购买或下载。我猜我必须编写自己的发现代理。我不是.NET或C++程序员,但我确实有Windows .CMD、VBA和PHP的经验,所以我理解编程。请您就我应该如何着手开发发现代理提出建议好吗?@BillVallance首先,您应该阅读我的答案。根据您的经验,您可以通过composer(我编写了用PHP实现的模块-ws-discovery)来提取逻辑/ws-discovery,然后您将需要通过HTTP实现SOAP,以便向外部世界提供发现代理服务。@Vladimir Bashkirtsev,非常感谢您的链接!我去看看,看能不能弄明白。