Defining the contract
Unlike ASP.NET web services, WCF truly promotes a "contract first" design style where developers need to thoughtfully consider how the outside world will interact with their service. There is a clean separation between the interface definition and the actual implementation of the service. When building ASP.NET services, the developer typically takes a code-first approach, where .NET classes are decorated with attributes and exposed as services. In the WCF model, we focus first on the data being shared and what our interface to the outside world should look like (the contract). Only after this critical step is complete does the WCF developer begin to design the actual service implementation logic.
There are actually three different contracts that you may define for a WCF service:
- Service contract
- Data contract
- Fault contract
There's actually a fourth contract type corresponding to the message, but I won't be covering that here. We'll investigate...