web-serviceswcfwcf-bindingwcf-discoverywebservice-discovery

WCF service discovery with metadata


Hi I'm looking for a WCF example which include service discovery and a way to discover/detect the binding type, I think it could be done using metadata exchange .


Solution

  • I just found the correct answer, here are the steps to complete the task:

    1. Add a mex endpoint.
    2. Add metadata exachange behaviour.
    3. in the client application use discovery with metadata criteria.

    Discovery with metdatada criteria

    DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
    FindCriteria findCriteria =   FindCriteria.CreateMetadataExchangeEndpointCriteria    (ContractType);
        findCriteria.Duration = TimeSpan.FromSeconds(15);
        findCriteria.MaxResults = 1;// MaxResults;
    
        FindResponse result = discoveryClient.Find(findCriteria);
        discoveryClient.Close();
    
    
        ServiceEndpointCollection eps = MetadataResolver.Resolve(ContractType, result.Endpoints[0].Address);
        return eps[0].Binding;