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