Chapter 2. Service Contracts and Data Contracts

WHAT'S IN THIS CHAPTER?

  • Explaining contracts

  • Implementing service contracts

  • Implementing data contracts

  • Using different serializers

  • Implementing message contracts

Contracts in general are very important in our daily lives. Contracts ensure that each party is aware of what his or her efforts will return. If you put your signature at the end of 17 pages of a business document or make a verbal agreement, expectations are given and agreed on. A contract should be well-defined and understandable without leaving any leeway for interpretation.

One thing is certain: in a service-oriented environment where different parties (software components) communicate with each other and use different technologies and platforms, it is indispensable to have a clear definition of the how and what.

WCF (Windows Communication Foundation) uses the concept of contracts to define the service and its operation as a whole, to explain the data which are transferred by wire, and if needed, to directly define the SOAP messages exchanged between the client and the service. WCF uses WSDL and XSD to deliver service metadata.

WCF differentiates between three types of contracts: service, data, and message.

Each of these contracts defines a certain behavior. The one needed depends on your architecture. The most frequently used contract type is the service contract — it can be used in nearly every scenario. The service contract also stands for the C in the ABC of an endpoint. As ...

Get Professional WCF 4: Windows Communication Foundation with .NET 4 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.