Wednesday, November 22, 2017

OWIN

OWIN is not a framework. OWIN is a specification on how web servers and web applications should be built in order to decouple one from another and allow movement of ASP.NET applications to environments where at the current state it is not possible.

From Owin.org

OWIN defines a standard interface between .NET web servers and web applications. The goal of the OWIN interface is to decouple server and application.

Lack of ASP .Net

It had lacked some basic qualities like portability, modularity and scalability

What problems does it solve?

Before Owin ASP .Net application were tightly coupled  with IIS because of heavy dependency on System.Web.


System.Web which in turn heavily depends on IIS for providing many of the web infrastructure features like request/response filtering, logging, etc.

System.Web assembly also includes many default components that are plugged into the Http pipeline regardless of its usage in the application. This means there are some unwanted features  (such as Web Forms or URL Authorization) that are executed in the pipeline for every request which degrades the performance. This has made the current open source counter-parts like NodeJs, Ruby, etc. perform way better than Asp.Net framework.

So OWIN itself does not have any tools, libraries or anything else. It is just a specification.

What is Katana?

Katana on the other hand, is fully developed framework made to make a bridge between current ASP.NET frameworks and OWIN specification. 

Host Option

When deciding how will you host your web server, you had two options:

  • IIS
  • Self-Host

IIS is good, resourceful host for web servers. Entire ASP.NET performance issue with using IIS has deep roots in System.Web only. Up until the recent time, 

So if you wanted a performance, you'd go for self-host option. If you wanted a lot of out-of-the-box features that IIS provides, you'd go for IIS but you'd lose on performance.


Now, there is a 3rd option, a Microsoft library named Helios (current codename) which intends to remove System.Web out of the way, and allow you to use IIS on more "cleaner" way, without any unnecessary libraries or modules. Helios is now in pre-release version, and is waiting for more community feedback in order to make it fully supported Microsoft product.

OWIN components

There are only two main pieces in OWIN

An environment dictionary   This dictionary is passed to  our application by the server with request and response header and bodies.Our application works directly  with this dictionary instead of communicating with the server.It is this dictionary which helps create the decoupled OWIN architecture.

A generic Func delegate  This delegate takes as a parameter the above mentioned environment dictionary and returns a Task.We can plugin different middleware components using this.

The environment dictionary can contain only the designated keys.Some of the keys related to the Request are

Key 
Description

"owin.RequestBody"
A Stream with the request body

"owin.RequestHeaders"
A IDictionary containing request headers. 

"owin.RequestMethod"
A string containing the HTTP method of the request (GET, POST etc. )

"owin.RequestPath"
A string which contains the request path

"owin.RequestPathBase"
A string which contains the portion of the request path corresponding to the "root" of the application delegate

"owin.RequestProtocol"
A string which contains the protocol name and version (HTTP/1.0, HTTP/1.1  etc.)

Following happens when the host starts

  • The environment dictionary is created  by the Host and passed to the server.Host also populates this  ,prior to passing this to the server,to inform the server about itself.
  • Server populates this dictionary to announce  its capabilities to other OWIN components, like our application and the server.
  • Host passes the dictionary to our application's setup code.
  • Our application creates the request pipeline and returns the generic Func delegate.
  • Host now starts the server by launching the server startup code with the dictionary and the delegate.
After the above steps have completed the server is ready accept the requests using the delegate passed to it by our application.

As we saw host is responsible for creating the server ,as well as communicating with our application to create the  request pipeline.

Katana Implementation of  OWIN









1 comment:

Unknown said...

Ohayo,

Nice to be visiting your blog again, it has been months for me. Well this article that i’ve been waited for so long.
I want to display tree grid which contain tab details like the attachament. Means when user click on any tree grid item then he will get expanded result in tab format like this which you can see in attached documents. ASP .Net

But nice Article Mate! Great Information! Keep up the good work!

Many Thanks,
Radhey

Followers

Link