---
title: "WCF Contracts."  
description: "Contracts in WCF  In WCF, all services expose contracts. The contract is a  platform-neutral and standard way of describing what the service does. In"  
author: "James Smith"  
published: 2011-08-01  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/212/wcf-contracts  
category: "wcf"  
tags: ["wcf"]  
reading_time: 2 minutes  

---

# WCF Contracts.

## Contracts in WCF

\

**In WCF, all [services](https://www.mindstick.com/articles/13111/distinctions-of-iiot-services-how-its-helps-brands) expose contracts.** The contract is a [platform](https://www.mindstick.com/articles/13080/wikipedia-the-most-powerful-advertising-platform-of-the-digital-age)-neutral and standard way of describing what the service does. In this blog I will told you that which type of contracts available in WCF and how we can use them. This blog is only provides an introductory [knowledge](https://www.mindstick.com/forum/156160/what-is-google-knowledge-graph) in WCF contracts.

WCF defines four types of contracts.

## Service contracts

\

Service contracts define which type of [operations](https://www.mindstick.com/blog/304985/how-does-devops-bridge-the-gap-between-development-and-operations-teams-like-git) the client can perform on the service. We used two types of [attributes](https://www.mindstick.com/articles/13105/2-attributes-that-make-your-odoo-ecommerce-theme-productive-and-engaging) to define service contract.

**ServiceContract** - This [attribute](https://www.mindstick.com/blog/221/attributes-reflection) is used to define the [Interface](https://www.mindstick.com/articles/12101/interfaces-in-java-extending-interfaces).

OperationContract - This attribute is used to define the method inside Interface.

### Example of service contracts

\

[ServiceContract]

interface IServiceContract

{

[OperationContract]

string MyMethod( );

}

class Service : IServiceContract

{

public string HelloWorld( )

{

return "[Hello World](https://www.mindstick.com/forum/12912/how-to-show-hello-world-backbone-marionette-js)";

}

}

## Data contracts

\

Data contracts define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.

There are two types of Data Contracts.

**DataContract** –DataContract attribute used to define the class

**DataMember** –DataMember attribute used to define the [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties).

### Example of Data contracts

\

[DataContract]

class ServiceContract

{

[DataMember]

public string Name;

[DataMember]

public string City;

}

If DataMember attributes are not specified for a properties in the class that property can't be passed to-from [web service](https://www.mindstick.com/articles/895/web-service-introduction).

## Fault contracts

Define which errors are raised by the service, and how the service handles and propagates errors to its clients.

## Message contracts

**\**

Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability cases and when there is an existing message format we have to comply with.

---

Original Source: https://www.mindstick.com/blog/212/wcf-contracts

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
