Client to Service Communication Process
DCS Dynamic Messaging Patterns separate callers from the physical endpoints of services. To identify the implementation of a service unambiguously, Dynamic Messaging Patterns use the name of the contract (the interface) exposed by the service itself.
On the caller side, Dynamic Messaging Patterns must abstract the actual service location from its contract. In the DCS model, the caller calls a contract as if it was local. The caller does not need to know the location or the details of the communication. To mask these details, the communication is performed in three stages, as follows:
- Using the contract to be called and the client scope, DCS initiates a WS-Discovery session to recover all of the instances available for that contract and in that scope. (For more information about discovery, see the next section, DCS Discovery Service.) The scope is matched hierarchically, and a list of the matching instances is returned. The client has a pluggable component that is responsible for choosing the right instance from the list. The DCS standard implementation of the contract selects the most scope-specific instance available. If two instances are equally specific, DCS returns the first one that it locates.
- After an instance is located, a WS-MetadataExchange communication is performed to determine the policies exposed by that service instance. Each policy is mapped to a configurable set of components called policy importers, whose function is to select the appropriate behaviors as determined by the policy. The behaviors are configured as WCF custom bindings and are inserted automatically in the send pipeline to communicate with the service instance.
- When steps 1 and 2 are completed, the communication proceeds without intermediaries.
DCS Dynamic Messaging Patterns does not need to create the service addresses (endpoints) for the caller to use, but instead uses a custom implementation of the WS-Discovery protocol to determine at run time which service instances implement a given contract.
In brief, DCS Dynamic Messaging Patterns uses the following logic to find the service to call:
- If there is an endpoint in the local configuration for the contract, DCS Dynamic Messaging Patterns uses that endpoint to call the service.
- If no local endpoint is available, DCS Dynamic Messaging Patterns contacts the Discovery Service, which returns the list of services that can implement a valid response for the current context. DCS Dynamic Messaging Patterns selects the best service from the list, and then uses the WS-Metadata Exchange protocol to request the policies and service configuration information. It then configures the endpoint so that it can communicate with the service.
- To limit future round trips, DCS Dynamic Messaging Patterns caches the results of the Discovery operation and metadata obtained by the service.