Discovery with Scopes Sample

The DiscoveryWithScopes sample shows how to use scopes to categorize discoverable endpoints as well how to use DiscoveryClient to perform an asynchronous search for endpoints. On the service, this sample shows how to customize discovery for each endpoint by adding an endpoint discovery behavior and using it to add a scope to the endpoint as well as controlling the endpoint's discoverability. On the client, the sample goes over how clients can create a DiscoveryClient and fine tune search parameters to include scopes by adding scopes to the FindCriteria. This sample also shows how clients can restrict responses by adding a termination criterion.

Service Features

This project shows two service endpoints being added to a ServiceHost. Each endpoint has a EndpointDiscoveryBehavior associated with it. This behavior is used to add URI scopes for both endpoints. Scopes are used to distinguish each of these endpoints so that the clients can fine tune the search. For the second endpoint, the discoverability can be disabled by setting the Enabled property to false. This ensures that the discovery metadata associated with this endpoint is not sent as part of any discovery messages.

Client Features

The FindCalculatorServiceAddress() method shows how to use a DiscoveryClient and pass in a FindCriteria with two restrictions. A scope is added to the criteria and the MaxResults property is set to 1. The scope limits the results to only the services that publish the same scope. Setting MaxResults to 1 limits the responses the DiscoveryClient waits for to, at most, 1 endpoint. The Find call is a synchronous operation that blocks the thread until a timeout is reached or one endpoint is found.

To use this sample

  1. This sample uses HTTP endpoints and to run this sample, proper URL ACLs must be added. For more information, see Configuring HTTP and HTTPS. Executing the following command at an elevated privilege should add the appropriate ACLs. You may want to substitute your Domain and Username for the following arguments if the command does not work as is: netsh http add urlacl url=http://+:8000/ user=%DOMAIN%\%UserName%

  2. Build the solution.

  3. Run the service executable from the build directory.

  4. Run the client executable. Note that the client is able to locate the service.