This post discusses the Consumer Driven Contract pattern and the use of that pattern in the BizTalk LOB adapter framework. Note that the LOB adapters are built on WCF and are not dependent on BizTalk Server. No knowledge of BizTalk Server is required to work with the LOB adapters SDK.
Consumer driven contracts is a pattern that suggests a consumer will only use those parts of a contract published by a provider that is of direct use to that consumer. The consumer will then only have a dependency on a sub-set of the provider contract and will therefore be impacted less by change. Ian Robinson wrote an article on the subject that can be found at Microsoft Msdn or at Martin Fowler’s site. The article suggests that a provider should accommodate the expectations of its consumers in such a way that changes to the service will impact the consumer as little as possible and independent (between service and consumer but also between different consumers of the same service) versioning is possible. So now we have two (types of) contracts. A provider contract that communicates all the capabilities of the service and a consumer contract; a sub-set of the provider contract a consumer actually uses. One service typically has one provider contract (unless it is specifically build to act on more than one –version of a- contract) and may have many consumer contracts.
One of the current technologies that uses the consumer driver contracts pattern is the LOB adapters of BizTalk. The LOB adapters are built on WCF and can be used separate of BizTalk Server. The LOB adapter framework is designed to expose legacy (line of Business) systems as web services. The service author has to implement four aspects to satisfy the framework.
The service implementation should be able to connect to the legacy system.
- Metadata browsing
The service implementation returns a collection of available ‘operations’. One or more of these operations can be selected by the consumer. This is an implementation of the consumer driven contract at operation level.
- Metadata resolvement
The operations selected by the consumer need to be resolved to callable methods.
The service needs to be able to receive request messages for the operations and send back response messages (when appropriate).
When a service implements these facilities the framework will generate its Wsdl, perform connection pooling, do transactions and handle security. A consumer of a LOB adapter service can use the new ‘Add Adapter Service Reference’ menu option in Visual Studio to reference an LOB service and select the methods with a new UI. The UI allows you to make a connection to a service, browse and search its metadata and select which methods you want to consume from the service. This new UI is also available in BizTalk server when consuming an adapter service in BizTalk.
Both the Consumer Driven Contract pattern and the LOB adapter SDK are interesting for Service Oriented Architectures. The pattern will reduce coupling between consumer and service, which is good for evolving your SOA and the LOB adapter SDK will provide you with a framework you can build on when service-enabling those legacy systems.
A blog post on msdn has some more resources on the LOB adapter framework.