Service Contract in WCF

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.
 
  1. Service Contract
  2. Operation Contract
Service Contract

The Service Contract declares an interface in the WCF service for the client to get access to the interface. 
  1. [ServiceContract]  
  2. interface ICustomer  
  3. {  
  4. }  
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

  1. [OperationContract]  
  2. Response AddNew(string customername);   

Example 2

  1. [ServiceContract]  
  2. interface ICustomer  
  3. {  
  4.    [OperationContract]  
  5.    Response AddNew(string customername);  
  6.    Response Delete(int customerID);  
  7. }   

 

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.