Message Contracts

When you define a service contract, you traditionally describe a set of operations that may include a parameter list and a return value. Each operation is ultimately linked to a request, a response message, or both in the service description, depending on the message exchange pattern for the operation. A message contract is a more formal way to describe operation messages. It gives you more granular control over the actual structure of the message (the SOAP envelope), which can be important for the web service savvy. You can use message contracts as the only parameter and as the return type for any operation, in lieu of a parameter list or return value-comprising data contracts or serializabletypes.

Data contracts are still very important to the message contract. In fact, message contracts internally describe what would have been a parameter list or return value. The value added by message contracts is in their ability to exercise greater control over how message headers and message body elements are serialized. The following attributes will be introduced in this section as I show you how to work with message contracts: MessageContractAttribute, MessageHeaderAttribute, and MessageBodyMemberAttribute.

Lab: Controlling Message Serialization with Message Contracts

In this lab, you will modify an existing service contract that uses traditional operation signatures and replace that approach with message contracts. A new message contract type will be created for each message. ...

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.