title: WCF web service discovery on network interfaces with multiple IP addresses
body: <p>I'm trying to do a webservice discovery using WCF's <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.discovery.discoveryclient(v=vs.100).aspx" rel="noreferrer"><code>DiscoveryClient</code></a> using this code:</p>
  
  <pre><code>// Setup the discovery client (WSDiscovery April 2005)
  DiscoveryEndpoint discoveryEndpoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);
  DiscoveryClient discoveryClient = new DiscoveryClient(discoveryEndpoint);
  
  // Setup the wanted device criteria
  FindCriteria criteria = new FindCriteria();
  criteria.ScopeMatchBy = new Uri("http://schemas.xmlsoap.org/ws/2005/04/discovery/rfc3986");
  criteria.Scopes.Add(new Uri("onvif://www.onvif.org/"));
  
  // Go find!
  criteria.Duration = TimeSpan.FromMilliseconds(duration);
  discoveryClient.FindAsync(criteria, this);
  </code></pre>
  
  <p>This works very well on a machine with a single IP address (10.1.4.25) assigned to the single network interface. The broadcast is sent from 10.1.4.25 to 239.255.255.250, and I get responses from 5 devices all on the same subnet.</p>
  
  <p>However, when the machine has multiple IPs on the same interface, it seems to pick a single source IP and sends the request from that.
  In this case, I get a reply from a single device giving a 169.254 address.</p>
  
  <p>I have tried setting <code>UdpDiscoveryEndpoint.TransportSettings.MulticastInterfaceId</code> to a suitable interface ID which hasn't helped as it identifies a single interface, not a specific IP.
  The <code>UdpDiscoveryEndpoint.ListenUri</code> property also returns the multicast address, and so won't effect the source IP.
  <code>UdpDiscoveryEndpoint.Address</code> is the URN for the discovery protocol.</p>
  
  <p>Is there any way I can force it to send from a specific IP address, or ideally, multiple requests on each configured IP?</p>
  
  <p>I have also tried <a href="http://sourceforge.net/p/onvifdm/" rel="noreferrer">ONVIF Device Manager</a> that seems to have the same problem.</p>
  
  <p>Note that this is not about making a service bind to a specific, or "all address" IP. It is about the IP a discovery request is sent from.</p>