Pergunta

I want to find a WCF service using it's address. I wrote the following code:

var uri = "http://bla-blabla.svc"
var obj = new DiscoveryClient(new UdpDiscoveryEndpoint());
        var findCriteria = new FindCriteria();
        findCriteria.Duration = TimeSpan.FromSeconds(10);
        findCriteria.Scopes.Add(new Uri(uri));
        var findResponse = obj.Find(findCriteria);

But it doesn't find anything... If I try to search using WCF test client using the link, it works... What I'm doing wrong?

Foi útil?

Solução

When you use WCF test client, you are not using the Discovery feature. It's a classic call to the wsdl/metadata of the service.

Your target Service should be discoverable, by adding something in the host or in the config.

Code

ServiceHost host = new ServiceHost(...); 
host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
ServiceDiscoveryBehavior discovery = new ServiceDiscoveryBehavior();
host.Description.Behaviors.Add(discovery);
host.Open();

Config

<services>
       <service name = "MyService">
          <endpoint 
             kind = "udpDiscoveryEndpoint"
          />
          ...
       </service>
    </services>
    <behaviors>
       <serviceBehaviors>
          <behavior>
             <serviceDiscovery/>
          </behavior>
       </serviceBehaviors>
    </behaviors>

At first, also remove the scope in the find criteria.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top