Discovery with Scopes Sample
This 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.
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.
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
This sample uses HTTP endpoints and to run this sample, proper URL ACLs must be added. See Configuring HTTP and HTTPS for details. 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%
Build the solution.
Run the service executable from the build directory.
Run the client executable. Note that the client is able to locate the service.
The samples may already be installed on your machine. Check for the following (default) directory before continuing.
If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.