Service Contracts

A service contract describes the operations supported by a service, the message exchange pattern they use, and the format of each message. The service contract is also the main driver for generating a service description. A valid WCF service implements at least one service contract. The following attributes play an important role in defining service contracts: ServiceContractAttribute, OperationContractAttribute, and MessageParameterAttribute. Collectively, these attributes provide control over the way messages are formatted.

In this section, the first thing you’ll do is complete a lab that exercises each of these attributes. Following the lab, I’ll summarize the features of each of these attributes and their roles in service contract design. In the process, I’ll also cover other related concepts such as:

  • How service contracts map to WSDL elements

  • Service contract design

  • Operations signatures and messages

  • Versioning scenarios

Lab: Designing a Service Contract

In this lab, you will begin with an existing solution that includes three projects: a service, a host, and a client. The solution includes a working implementation of a very simple service contract, and you will edit this implementation to exercise more control over the service contract to control the resulting service description. In the process, you’ll also test service contract version tolerance.

Exploring service contract compatibility

In the first part of this lab, you’ll modify an existing service contract to ...

Get Learning WCF now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.