What is OWIN?

By | April 16, 2017

A few posts back I was looking at OAuth and I stumbled onto some posts with references to this thing called OWIN. Initially I thought it was a framework that wrapped OAuth to make it easier to use but it turned out to be a hosting solution with support for middleware. 

Owin is a specification to allow web applications / services to be decoupled from its hosting technology.6 Katana is the codename of the project from Microsoft that is the realization of the OWIN specification. I started reading this post on katana that made it much more clear but in essence Katana provides three things.

  1. Separation of the application from the hosting technology. The application can be hosted within IIS, self hosted or within another 3rd party hosting solution without the need to have the application recompiled.
  2. An intercept able application pipeline, allows modules to intercept the requests/response of the application pipeline, these modules are called middleware. For me this seems very similar to the WCF aspect based programming although not identical.

Some things I notice

  • There only seems to be Http support. I don’t see support for net.tcp and msmq.
  • OWIN supports Web API but not WCF.
  • It appears like OWIN is build into Asp.net & MVC as de facto since Asp.net 5

Below is a very, very basic sample.

I build this Owin Sample by following the example on the katana post mentioned earlier, It is very very basic. If you download it please get the required nuget packages and rebuild. The only code that I added to the empty web application is the following.

using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(Owin.Startup))]

namespace Owin
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Run(context =>
{
context.Response.ContentType = "text/plain";

return context.Response.WriteAsync("Hello World");
});
}
}
}

The sample demonstrates the ability of the application to be hosted in IIS as well as being able to be self hosted without the need for changes to the code or for the code to be aware of the hosting solutions.

Here I am running the web application out of the development environment. The only way to notice that is by noting the port being used.

Next, I will running the web application using the Owin self hosting solution. To self host the web application you need to execute the following command from command prompt. Note that my working folder in this image is the project folder of my web application.

Once executed the command prompt will look like this.

Now you can see that the self hosting solution is hosting the application on a different port – 5000 and I will not browse to that location.

 

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *