---
title: "What is the difference between self-hosting and IIS-hosting in WCF?"  
description: "What is the difference between self-hosting and IIS-hosting in WCF?"  
author: "ICSM Computer"  
published: 2025-05-26  
updated: 2025-05-26  
canonical: https://www.mindstick.com/interview/34168/what-is-the-difference-between-self-hosting-and-iis-hosting-in-wcf  
category: "c#"  
tags: ["c#", "wcf"]  
reading_time: 4 minutes  

---

# What is the difference between self-hosting and IIS-hosting in WCF?

The main difference between **self-hosting** and **IIS-hosting** in WCF lies in **who controls the service lifecycle** and **what protocols are supported**. Here's a detailed comparison:

### 1. Hosting Control

| Feature | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| Service lifecycle | Controlled by your application code (`ServiceHost`) | Managed by IIS — automatic activation |
| Process management | Your app must start and keep the service alive | IIS handles process lifecycle |
| Manual setup required | Yes (write code to open/close host) | No (service activates on HTTP request) |

### 2. Supported Protocols

| Feature | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| HTTP | Yes | Yes |
| TCP, Named Pipes, MSMQ | Yes | No (unless using **WAS**) |
| Flexibility | High — supports all bindings | Limited to HTTP (IIS 7+ supports WAS for others) |

### 3. Deployment and Scalability

| Feature | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| Hosting environment | Console app, Windows Service, WPF/WinForms | IIS web server |
| Suitable for | Lightweight apps, internal tools, testing | Enterprise, production web services |
| Scalability | Manual load balancing required | Built-in scalability, process recycling |

### 4. Security and Monitoring

| Feature | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| Built-in security | Must be coded or configured manually | IIS provides integrated authentication, SSL |
| Logging/Monitoring | Manual setup or third-party tools | Built-in IIS logging and monitoring |

### Example of Self-Hosting

```plaintext
ServiceHost host = new ServiceHost(typeof(MyService));
host.Open();
Console.WriteLine("Service is running...");
Console.ReadLine();
host.Close();
```

### Summary

| Aspect | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| Startup | Manual | Automatic |
| Protocols | All (HTTP, TCP, Pipes, MSMQ) | Primarily HTTP (others via WAS) |
| Control | Full control by developer | Managed by IIS |
| Scalability | Manual | Built-in |
| Ideal For | Testing, internal tools, non-HTTP services | Web-based services requiring stability |

## Answers

### Answer by ICSM Computer

The main difference between **self-hosting** and **IIS-hosting** in WCF lies in **who controls the service lifecycle** and **what protocols are supported**. Here's a detailed comparison:

### 1. Hosting Control

| Feature | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| Service lifecycle | Controlled by your application code (`ServiceHost`) | Managed by IIS — automatic activation |
| Process management | Your app must start and keep the service alive | IIS handles process lifecycle |
| Manual setup required | Yes (write code to open/close host) | No (service activates on HTTP request) |

### 2. Supported Protocols

| Feature | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| HTTP | Yes | Yes |
| TCP, Named Pipes, MSMQ | Yes | No (unless using **WAS**) |
| Flexibility | High — supports all bindings | Limited to HTTP (IIS 7+ supports WAS for others) |

### 3. Deployment and Scalability

| Feature | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| Hosting environment | Console app, Windows Service, WPF/WinForms | IIS web server |
| Suitable for | Lightweight apps, internal tools, testing | Enterprise, production web services |
| Scalability | Manual load balancing required | Built-in scalability, process recycling |

### 4. Security and Monitoring

| Feature | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| Built-in security | Must be coded or configured manually | IIS provides integrated authentication, SSL |
| Logging/Monitoring | Manual setup or third-party tools | Built-in IIS logging and monitoring |

### Example of Self-Hosting

```plaintext
ServiceHost host = new ServiceHost(typeof(MyService));
host.Open();
Console.WriteLine("Service is running...");
Console.ReadLine();
host.Close();
```

### Summary

| Aspect | **Self-Hosting** | **IIS-Hosting** |
| --- | --- | --- |
| Startup | Manual | Automatic |
| Protocols | All (HTTP, TCP, Pipes, MSMQ) | Primarily HTTP (others via WAS) |
| Control | Full control by developer | Managed by IIS |
| Scalability | Manual | Built-in |
| Ideal For | Testing, internal tools, non-HTTP services | Web-based services requiring stability |


---

Original Source: https://www.mindstick.com/interview/34168/what-is-the-difference-between-self-hosting-and-iis-hosting-in-wcf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
