Search code examples
wcfws-discovery

Resolve a URI to an EndpointAddress


I currently have a WCF client that is able to do ad-hoc service discovery to find (unknown) services running on the local subnet. I would like to implement a way for the user to specify a service endpoint to use by entering a URI into a text box, and for the client to resolve this URI to an EndpointAddress, and in the process gather additional metadata about the service. Namely, I need to gather the EndpointIdentity and additional data exposed in the Extensions property of the EndpointDiscoveryBehavior.

I am trying to achieve this by using DiscoveryClient.Resolve(), but I am only receiving null for the ResolveResponse.EndpointDiscoveryMetadata property.

String Address = "net.tcp://machine-name:12345/MyService"
DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
var criteria = new ResolveCriteria()
{
    Address = new EndpointAddress(Address)
};
var result = discoveryClient.Resolve(criteria);
//scv is null here.....
var svc = result.EndpointDiscoveryMetadata;

I've found a lot of information out there regarding DiscoveryClient.Find(), but not so much about DiscoveryClient.Resolve().

So my questions are:

  • Is this the intended use of DiscoveryClient.Resolve()?
  • Is MetadataResolver more appropriate here?
  • How does one resolve an URI to a EndpointAddress and obtain other metadata?

Solution

  • I achieved what I wanted to do like so:

    String Address = "net.tcp://machine-name:12345/MyService"
    DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
    var endpoint = new EndpointAddress(new Uri(Address));
    var criteria = new ResolveCriteria()
    {
        Address = endpoint
    };
    var result = discoveryClient.Resolve(criteria);
    
    var mexClient = new MetadataExchangeClient(MetadataExchangeBindings.CreateMexTcpBinding());
    var contracts = new List<ContractDescription>() { ContractDescription.GetContract(typeof(RuntimeService.Services.IWorkflowService)) };
    var metaResult = MetadataResolver.Resolve(contracts, endpoint, mexClient);
    
    var svc = metaResult.First();
    

    I am able to get to the extension data through result and svc provides me with the correct EndpointAddress complete with the correct identity.

    Thanks to @YK1 for pushing me in the right direction.