---
title: "What is the difference between PerCall, PerSession, and Single instance modes?"  
description: "What is the difference between PerCall, PerSession, and Single instance modes?"  
author: "ICSM Computer"  
published: 2025-05-27  
updated: 2025-05-27  
canonical: https://www.mindstick.com/interview/34170/what-is-the-difference-between-percall-persession-and-single-instance-modes  
category: "c#"  
tags: ["c#", "wcf"]  
reading_time: 4 minutes  

---

# What is the difference between PerCall, PerSession, and Single instance modes?

In WCF, **PerCall**, **PerSession**, and **Single** are **instance context modes** that define how and when WCF service instances are created and reused during client communication.

### 1. PerCall

1. **Description**: A **new service instance** is created for **every method call** from any client.
2. **State**: **Not maintained** between calls.
3. **Concurrency**: No synchronization needed.
4. **Use case**: Stateless operations (e.g., utility services, logging).

```cs
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
```

| Feature | Value |
| --- | --- |
| Instance Scope | Per method call |
| State Retention | No |
| Scalability | High |

### 2. PerSession

- **Description**: A **single instance** is created for the **lifetime of a client session**.
- **State**: Maintained throughout the session.
- **Concurrency**: Needed if multiple threads are involved.
- **Use case**: Services that require state tracking per client (e.g., shopping cart, workflow).

```cs
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
```

| Feature | Value |
| --- | --- |
| Instance Scope | Per client session |
| State Retention | Yes (per client) |
| Scalability | Medium |
| Requires Sessions | Yes (`NetTcp`, etc.) |

### 3. Single (Singleton)

- **Description**: A **single service instance** is created and shared across **all clients and all calls**.
- **State**: Shared across all clients.
- **Concurrency**: Critical — must handle simultaneous access.
- **Use case**: Centralized resource sharing, caching, or coordination services.

```cs
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
```

| Feature | Value |
| --- | --- |
| Instance Scope | Entire application |
| State Retention | Yes (shared) |
| Scalability | Low |
| Concurrency | Must be handled |

### Summary Table

| Mode | Instance Created When | State Retained | Suitable For | Needs Concurrency Handling |
| --- | --- | --- | --- | --- |
| PerCall | On every operation call | No | Stateless services | No |
| PerSession | Once per client session | Yes (per client) | Stateful workflows | Yes |
| Single | Once per application | Yes (shared) | Shared-state services | Yes |

## Answers

### Answer by ICSM Computer

In WCF, **PerCall**, **PerSession**, and **Single** are **instance context modes** that define how and when WCF service instances are created and reused during client communication.

### 1. PerCall

1. **Description**: A **new service instance** is created for **every method call** from any client.
2. **State**: **Not maintained** between calls.
3. **Concurrency**: No synchronization needed.
4. **Use case**: Stateless operations (e.g., utility services, logging).

```cs
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
```

| Feature | Value |
| --- | --- |
| Instance Scope | Per method call |
| State Retention | No |
| Scalability | High |

### 2. PerSession

- **Description**: A **single instance** is created for the **lifetime of a client session**.
- **State**: Maintained throughout the session.
- **Concurrency**: Needed if multiple threads are involved.
- **Use case**: Services that require state tracking per client (e.g., shopping cart, workflow).

```cs
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
```

| Feature | Value |
| --- | --- |
| Instance Scope | Per client session |
| State Retention | Yes (per client) |
| Scalability | Medium |
| Requires Sessions | Yes (`NetTcp`, etc.) |

### 3. Single (Singleton)

- **Description**: A **single service instance** is created and shared across **all clients and all calls**.
- **State**: Shared across all clients.
- **Concurrency**: Critical — must handle simultaneous access.
- **Use case**: Centralized resource sharing, caching, or coordination services.

```cs
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
```

| Feature | Value |
| --- | --- |
| Instance Scope | Entire application |
| State Retention | Yes (shared) |
| Scalability | Low |
| Concurrency | Must be handled |

### Summary Table

| Mode | Instance Created When | State Retained | Suitable For | Needs Concurrency Handling |
| --- | --- | --- | --- | --- |
| PerCall | On every operation call | No | Stateless services | No |
| PerSession | Once per client session | Yes (per client) | Stateful workflows | Yes |
| Single | Once per application | Yes (shared) | Shared-state services | Yes |


---

Original Source: https://www.mindstick.com/interview/34170/what-is-the-difference-between-percall-persession-and-single-instance-modes

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
