---
title: "What is the purpose of a contract in WCF? Name different types."  
description: "What is the purpose of a contract in WCF? Name different types."  
author: "ICSM Computer"  
published: 2025-05-26  
updated: 2025-05-26  
canonical: https://www.mindstick.com/interview/34164/what-is-the-purpose-of-a-contract-in-wcf-name-different-types  
category: "c#"  
tags: ["c#", "wcf"]  
reading_time: 2 minutes  

---

# What is the purpose of a contract in WCF? Name different types.

In WCF, a **contract** defines what a service does — essentially the **interface** between the client and the service. It specifies the operations (methods), data structures, messages, and faults the service supports.

### Purpose of a Contract in WCF

1. Describes the service functionality to clients.
2. Allows WCF to generate service metadata (WSDL).
3. Defines how data is structured and communicated.
4. Enables separation of implementation from definition.

### Types of Contracts in WCF

1. **Service Contract**

   1. Defines the operations the service exposes.
   2. Applied to interfaces or classes using `[ServiceContract]` and `[OperationContract]`.

2. **Data Contract**

   1. Defines how complex data types are serialized and deserialized.
   2. Uses `[DataContract]` and `[DataMember]`.

3. **Message Contract**

   1. Provides full control over the SOAP message format (headers, body, etc.).
   2. Used when you need to customize message structure.

4. **Fault Contract**

   1. Defines structured error information sent to clients.
   2. Uses `[FaultContract]` to declare expected faults.

### Summary

1. A **contract** defines the behavior, data, and communication structure of a WCF service.
2. Main types: **Service**, **Data**, **Message**, and **Fault** contracts.
3. Contracts enable WCF to enforce a strong and flexible service interface model.

## Answers

### Answer by ICSM Computer

In WCF, a **contract** defines what a service does — essentially the **interface** between the client and the service. It specifies the operations (methods), data structures, messages, and faults the service supports.

### Purpose of a Contract in WCF

1. Describes the service functionality to clients.
2. Allows WCF to generate service metadata (WSDL).
3. Defines how data is structured and communicated.
4. Enables separation of implementation from definition.

### Types of Contracts in WCF

1. **Service Contract**

   1. Defines the operations the service exposes.
   2. Applied to interfaces or classes using `[ServiceContract]` and `[OperationContract]`.

2. **Data Contract**

   1. Defines how complex data types are serialized and deserialized.
   2. Uses `[DataContract]` and `[DataMember]`.

3. **Message Contract**

   1. Provides full control over the SOAP message format (headers, body, etc.).
   2. Used when you need to customize message structure.

4. **Fault Contract**

   1. Defines structured error information sent to clients.
   2. Uses `[FaultContract]` to declare expected faults.

### Summary

1. A **contract** defines the behavior, data, and communication structure of a WCF service.
2. Main types: **Service**, **Data**, **Message**, and **Fault** contracts.
3. Contracts enable WCF to enforce a strong and flexible service interface model.


---

Original Source: https://www.mindstick.com/interview/34164/what-is-the-purpose-of-a-contract-in-wcf-name-different-types

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
