Sample application using OWIN Self-hosting

facebooktwittergoogle_plusredditpinterestlinkedinmail

This article will demonstrate a sample application using OWIN Self-hosting. I believe you have basic understanding about OWIN and Katana if not please read introduction to OWIN and Katana article first.

Step1 : Create a console application.

Create a console application

Step2: Add the Nuget package : Microsoft.Owin.SelfHost

Microsoft.Owin.SelfHost

After adding package you will get nice readme text, that tells what exactly we need to do to get started.

Step3: Create a startup class and write the OWIN pipeline configuration. Here i have added delegate based middle-ware.

 public class Startup
    {
        public static void Configuration(IAppBuilder app)
        {
            app.Use(async (x, next) => {
                await x.Response.WriteAsync("Welcome to OWIN self hot");
            });
        }
    }

Step4: Copy the implementation from readme text and paste it in program.cs file.

using (WebApp.Start<Startup>("http://localhost:12345"))
{
    Console.ReadLine();
}

We are done with coding. Just run the application. An empty console will be displayed. Enter http://localhost:12345 in the browser. You can see the hosted application.

OWINSelf4

We get the content in the browser. The self-hosted OWIN pipeline is responded when we send the request.

The following two tabs change content below.

Tom Mohan

Tom Mohan is a technologist who loves to code and build. He enjoys working on Microsoft Technologies. Tom specializes in ASP.NET MVC, Web API , Azure, C# ,WPF, SQL etc and holds a Bachelor engineering degree in Computer Science. Certification : MCSD , MCTS