문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top