In this article we are going to learn how to host an ASP.NET Web API in a console application, using OWIN to self-host the Web API framework.
Introduction
In this article we will learn how to host an ASP.NET Web API in a console application, using the Open Web Interface for .NET (OWIN) to self-host the Web API framework.OWIN defines the abstraction between .NET web servers and web applications. In a general scenario the OWIN decouples with the web application from the server, that makes OWIN as a self-hosting a web application for our own process, that is absent of IIS.Before the start of OWIN Self Hosting applications let's try to understand the self hosting using my old article. According to this article we will be able to understand the basics of Self Hosting.
Now we are able to start learning the OWIN self hosting application step-by-step.Step 1 Create a Console Application.To create a Console application we need to use a basic procedure. Click on the File menu and choose New, then click Project. After getting the project we need to specify the language from the Installed Templates, so we will choose Visual C#, and click Windows and then click Console Application. Now we can provide a nice name for the application.Step 2Add the Web API and OWIN PackagesThere are two ways to install the OWIN package using the Nuget Package manager. First we need to only right-click on the Project from the Solution Explorer and select the NuGet Package Manager and search the OWIN self-host package. We will be able to see many applications listed below. In those we need to select the appropriate package. Secondly we need to click on the Tools menu, then click Library Package Manager, then click Package Manager Console. In the Package Manager Console window, enter the following command:Install-Package Microsoft.AspNet.WebApi.OwinSelfHostAccording to this command we will able to install the WebAPI OWIN selfhost package and all the required OWIN packages.Step 3Add the student class.In this class we will set the property of the student.
<< Getting Started With ASP.Net Web API 2 : Day 10
Getting Started with ASP.NET 4.5 Web Forms and Visual Studio 2013