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 use an explicit contract name and namespace
while testing compatibility between proxy and service as changes are made.
1. Start by opening the solution for this lab: <YourLearningWCFPath>\Labs\Chapter2\ServiceContracts\ServiceContracts.sln.
2. Test the solution first to see that it works.
Compile the solution and run the Host project followed by the WinClient project.
From the WinClient application interface,click each button to test the two operations exposed by the service contract: Operation1( ) and Operation2( ).
3. Review how the service you just tested is implemented.
Go to the BusinessServices project and open IServiceA.cs. Example 2-3 shows the service contract,which defines two operations.