The Service Contracts describes what action a client can perform in a service. This attribute is in theSystem.ServiceModel namespace. There are the following two types.
- Service Contract
- Operation Contract
Service Contract
The Service Contract declares an interface in the WCF service for the client to get access to the interface.
- [ServiceContract]
- interface ICustomer
- {
- }
Operation Contract
The Operation Contract declares a function inside the interface, the client will call this function. If you don't use the Operation contract in the preceding function then the client will not be able to call the function.
Example 1
- [OperationContract]
- Response AddNew(string customername);
Example 2
- [ServiceContract]
- interface ICustomer
- {
- [OperationContract]
- Response AddNew(string customername);
- Response Delete(int customerID);
- }
In the preceding Example 2 the clients will not be able to call the function name delete because the delete function has not used the Operation Contract.
Summery
Hope you have understood about service contract of WCF service.