WCF Contracts

  • Posted on : September 7, 2011
  • Modified: February 24, 2022

  • Author : SPEC INDIA
  • Category : Web Development

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

Service 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
interface ICurrencySymbol
string GetCurrencySymbol( );

// Implementation of the interface
class CurrencyService : ICurrencySymbol
public string GetCurrencySymbol (string currencyName )
If(currencyName == “India”)
return “RS”;

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;
Message Contract:
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.
Fault Contract:
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.


less words, more information

IN 200

Read our microblogs

Subscribe Now For Fresh Content


Guest Contribution

We are looking for industry experts to contribute to our blog section through fresh and innovative content.

Write For Us

Our Portfolio

Proven Solutions Across Industries
Technology for Real-Life

Visit Our Portfolio