September 7, 2011
Hello friends, in this article I am going to explain WCF contracts. WCF contracts means it describes the behavior of your service. In real world contracts are platform-neutral & identify what service does when any portal access it via end points.
There are mainly 4 different kinds of contract
This defines what operation the calling application can perform on the service. There are two types of service contract. The service contract identifies what service can be provided, for example you have one method which return currency symbol when passed with currency name as a function parameter.
ServiceContract: This is mainly use to define the interface.
OperationContract: This is used to design body of the methods or implementation of methods declared in the interface.
Following is one code sample for the service contract.
//Declaration for the service contract and operation contract
string GetCurrencySymbol( );
// Implementation of the interface
class CurrencyService : ICurrencySymbol
public string GetCurrencySymbol (string currencyName )
If(currencyName == “India”)
Data Contract: Data
This defines the declaration and identification of what data types are passed to and from you WCF service. WCF identify data contract for int & string data types explicitly but we can also have custom & optional data types defined with data contact. The data member defines the member of your class data type. If DataMember attributes are not specified for a properties in the class that property can’t be passed to-from web service.
Public class Currency
Private string _currencyName;
The message contract allows the service to communicate directly with the message. It is mainly type or untyped and used when there is some specific format of message passing in used. Also used for the multi platform supports.
The fault contract is mainly use to identify which errors are raised by the services and how it can be handled for the client display when it makes a call to the service.
SPEC INDIA, as your single stop IT partner has been successfully implementing a bouquet of diverse solutions and services all over the globe, proving its mettle as an ISO 9001:2015 certified IT solutions organization. With efficient project management practices, international standards to comply, flexible engagement models and superior infrastructure, SPEC INDIA is a customer’s delight. Our skilled technical resources are apt at putting thoughts in a perspective by offering value-added reads for all.