Building a Custom Scope Provider and Ranker

The Discovery Service uses scopes to help determine which service or services can satisfy a request sent by a client. The scope building and ranking process occurs as follows:

  1. The DCS client application provides context information as part of each request that it sends.
  2. The client proxy for the application identifies a scope provider, and the scope provider uses the context information to construct a list of scopes.
  3. The Discovery Service returns a list of service endpoints for all services that expose a data contract that satisfies the client request and that have scopes that match an item in the scope list.
  4. The client proxy identifies a scope ranker, which determines the priority order (or ranking ) of the service endpoints in the list returned by the Discovery Service.
  5. The proxy selects the first endpoint in the ranked list to connect to the service.
  6. If the connection to the selected service endpoint fails, the proxy retrieves the next endpoint from the ranked list and attempts to use that. The proxy sends a connectivity exception to the client application only if it reaches the end of the ranked list and the last endpoint fails. For more information on scopes and the discovery process, see DCS Scopes and How a DCS Client Invokes an Operation.

DCS provides a default scope provider named Microsoft.ConnectedIndustry.ServiceModel.Application.ScopeProvider. The default provider is in the Microsoft.ConnectedIndustry.ServiceModel.Application assembly. The ScopeProvider class generates scopes based on information specified in the Context object provided by a client request. You can extend the DCS Context class with a customized class that includes additional properties specific to your organization. For more information, see Building a Custom Context Class. By building a custom scope provider, you can include information from these additional properties in the scope information that the client proxy sends to the Discovery Service, and you can add scopes that reference these properties to DCS.

DCS provides a default scope ranker named Microsoft.ConnectedIndustry.ServiceModel.Application.ScopeRanking. The default ranker is in the Microsoft.ConnectedIndustry.ServiceModel.Application assembly. The ScopeRanking class orders service endpoints beginning with the endpoint that has the most specific match to the scope information provided by the client application, and ending with the scopes that have less specific matches. For more information on the default scope matching rules implemented by DCS, see DCS Scopes. A custom scope ranker lets you change the default order of the service endpoints presented to the client proxy, enabling you to take environmental or other considerations specific to your organization and location into account. For example, if a site in your organization is always heavily loaded on Wednesday afternoons, you can build a custom scope ranker that redirects requests from client applications to other sites at that time.

The topics in this section describe how to implement and configure a custom scope provider and a custom scope ranker.