Search code examples
c#wcfservice-discoveryws-discovery

WCF UDP discovery on other network


We have two different networks in our company, 17 and 18

  • 170.17.xxx.xxx
  • 170.18.xxx.xxx

On the 17 network there is a WCF service running which is discoverable. This is configured by the following code:

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);
}

A behavior with a scope is added to all non system endpoints and it can be discovered by sending udp packets over the network, a default instance of UdpDiscoveryEndpoint.

Clients discover the service by constructing a DiscoveryClient with a default UdpDiscoveryEndpoint.

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

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

FindResponse discovered = discoveryClient.Find(criteria);
discoveryClient.Close();

This works fine when both client and service run on the same network. But I would like to have a client running on the 18 network which is able to find the service on the 17 network.

So is it possible to discover services on other networks with DiscoveryClient and UdpDiscoveryEndpoint?

edit

Or can this be a firewall issue?


Solution

  • This is not a firewall issue but normal behavior of WS-Discovery. WS-Discovery uses SOAP-over-UDP sent to multicast IP group (239.255.255.250). And multicast packets generally are not routed and stay within limits of local network. Thus DiscoveryClient cannot discover services on other network without external help.

    You have two options:

    1. Configure your routers to pass multicast IP traffic between each other. While it is fairly easy to achieve it may load your inter-network link unnecessarily and it also may require help from your ISP or you may need tunneling of some sort.
    2. Set up what is known as "Discovery Proxy" on the network where discoverable services are. Discovery Proxy basically performs discovery locally and then uses HTTP to deliver discovery results to other networks. As Discovery Proxy has the same SOAP WSDL existing WS-Discovery clients may use it without any changes over internet.