title: "Self-Host ASP.NET Web API 1 (C#) | Microsoft Docs"
author: MikeWasson
description: "ASP.NET Web API does not require IIS. You can self-host a web API in your own host process. This tutorial shows how to host a web API inside a console applic..."
> ASP.NET Web API does not require IIS. You can self-host a web API in your own host process. This tutorial shows how to host a web API inside a console application.
>
> **New applications should use OWIN to self-host Web API.** See [Use OWIN to Self-Host ASP.NET Web API 2](../hosting-aspnet-web-api/use-owin-to-self-host-web-api.md).
>
> ## Software versions used in the tutorial
>
>
> - Web API 1
> - Visual Studio 2012
## Create the Console Application Project
Start Visual Studio and select **New Project** from the **Start** page. Or, from the **File** menu, select **New** and then **Project**.
In the **Templates** pane, select **Installed Templates** and expand the **Visual C#** node. Under **Visual C#**, select **Windows**. In the list of project templates, select **Console Application**. Name the project "SelfHost" and click **OK**.
![](self-host-a-web-api/_static/image1.png)
## Set the Target Framework (Visual Studio 2010)
If you are using Visual Studio 2010, change the target framework to .NET Framework 4.0. (By default, the project template targets the [.Net Framework Client Profile](https://msdn.microsoft.com/en-us/library/cc656912.aspx#features_not_included_in_the_net_framework_client_profile).)
In Solution Explorer, right-click the project and select **Properties**. In the **Target framework** dropdown list, change the target framework to .NET Framework 4.0. When prompted to apply the change, click **Yes**.
![](self-host-a-web-api/_static/image2.png)
## Install NuGet Package Manager
The NuGet Package Manager is the easiest way to add the Web API assemblies to a non-ASP.NET project.
To check if NuGet Package Manager is installed, click the **Tools** menu in Visual Studio. If you see a menu item called **Library Package Manager**, then you have NuGet Package Manager.
To install NuGet Package Manager:
1. Start Visual Studio.
2. From the **Tools** menu, select **Extensions and Updates**.
3. In the **Extensions and Updates** dialog, select **Online**.
4. If you don't see "NuGet Package Manager", type "nuget package manager" in the search box.
5. Select the NuGet Package Manager and click **Download**.
6. After the download completes, you will be prompted to install.
7. After the installation completes, you might be prompted to restart Visual Studio.
![](self-host-a-web-api/_static/image3.png)
## Add the Web API NuGet Package
After NuGet Package Manager is installed, add the Web API Self-Host package to your project.
1. From the **Tools** menu, select **Library Package Manager**. *Note*: If do you not see this menu item, make sure that NuGet Package Manager installed correctly.
2. Select **Manage NuGet Packages for Solution...**
3. In the **Manage NugGet Packages** dialog, select **Online**.
4. In the search box, type "Microsoft.AspNet.WebApi.SelfHost".
5. Select the ASP.NET Web API Self Host package and click **Install**.
6. After the package installs, click **Close** to close the dialog.
> [!NOTE]
> Make sure to install the package named Microsoft.AspNet.WebApi.SelfHost, not AspNetWebApi.SelfHost.
![](self-host-a-web-api/_static/image4.png)
## Create the Model and Controller
This tutorial uses the same model and controller classes as the [Getting Started](../getting-started-with-aspnet-web-api/tutorial-your-first-web-api.md) tutorial.
For more information about the code in this controller, see the [Getting Started](../getting-started-with-aspnet-web-api/tutorial-your-first-web-api.md) tutorial. This controller defines three GET actions:
| URI | Description |
| --- | --- |
| /api/products | Get a list of all products. |
| /api/products/*id* | Get a product by ID. |
| /api/products/?category=*category* | Get a list of products by category. |
## Host the Web API
Open the file Program.cs and add the following using statements:
## (Optional) Add an HTTP URL Namespace Reservation
This application listens to `http://localhost:8080/`. By default, listening at a particular HTTP address requires administrator privileges. When you run the tutorial, therefore, you may get this error: "HTTP could not register URL http://+:8080/" There are two ways to avoid this error:
- Run Visual Studio with elevated administrator permissions, or
- Use Netsh.exe to give your account permissions to reserve the URL.
To use Netsh.exe, open a command prompt with administrator privileges and enter the following command:following command:
1. Call **HttpClient.GetAsync** to send a GET request to the appropriate URI.
2. Call **HttpResponseMessage.EnsureSuccessStatusCode**. This method throws an exception if the HTTP response status is an error code.
3. Call **ReadAsAsync<T>** to deserialize a CLR type from the HTTP response. This method is an extension method, defined in **System.Net.Http.HttpContentExtensions**.
The **GetAsync** and **ReadAsAsync** methods are both asynchronous. They return **Task** objects that represent the asynchronous operation. Getting the **Result** property blocks the thread until the operation completes.
For more information about using HttpClient, including how to make non-blocking calls, see [Calling a Web API From a .NET Client](../advanced/calling-a-web-api-from-a-net-client.md).
Before calling these methods, set the BaseAddress property on the HttpClient instance to "`http://localhost:8080`". For example: