• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!



Page history last edited by Ryan Riley 13 years, 1 month ago

Open Web Interface for .NET (OWIN)





ASP.NET is difficult to test, not extensible due to sealed classes, etc.

Python has WSGI, Ruby has Rack, what about .NET?

More servers than IIS - Kayak, Manos de Mono, etc.

Frameworks end up building atop specific servers, which limits their mobility

We want a stackable approach to building web applications


What's included?

Gate - implementation of the OWIN spec using common primitives so as not to lock people in

Provides stackability and common middleware composition

Provides mobility on top of a number of web servers - IIS, HttpListener, WCFKayak, and more to come


What frameworks are using this?


Frank (in progress)


WCF Web API (compatible)


Who would use OWIN?

Host implementors

Framework creators

Web developer when creating the configuration to declare which server to use

Developers looking to leverage generic middleware:

  • Authorization (instead of hooking into ASP.NET event pipeline)
  • Load balancing?
  • Method Override
  • Exception handling
  • Logging


What does OWIN look like?

Interface version of an application:


// Close, but not equal, to the IObservable interface.

// The difference allows for a continuation to be called to facilitate pause/resume on the pipeline.

delegate IDisposable BodyDelegate( /* this is an asynchronous value producer */

    Func<ArraySegment<byte>, Action, bool> onData,


    Action completed); 

interface IApplication {

    void Invoke(IDictionary<string, object> env, Action<Exception> fault,

                      Action<string                                 /* 200 OK */,

                                  IDictionary<string, string> /* headers */,

                                  BodyDelegate                    /* response body */

                                > result);


No statics or other required state.

Lifecycle, state, etc. are all up to the host/framework implementor.

Can modify inner layers by wrapping with closures, i.e. man-in-the-middle


// onData in the BodyDelegate can also look like this:

interface IDataProducer {

    IDisposable Connect(IDataConsumer c);


interface IDataConsumer {

    // If you return true, OnData won't be called until the continuation c is called.

    // This allows buffers to drain.

    // Further, always returning true and calling the continuation can result in a StackOverflowException. 

    bool OnData(ArraySegment<byte> data, Action continuation);

    void OnError(Exception ex);

    void OnCompleted();



Discussion about different options:

  • IObservable / Rx
  • IDisposable instead of a bool with an implementation that communicates back a la node.js (not a good idea as that would require a reference to the socket and doesn't work well with async/await or F# Async). 
  • Definitely not final, but asynchronous streams coming in as requests and going out as responses can make this quite difficult.
  • Look into moving this contract into Rx? 


OWIN and You

Q: Would Orchard be able to take advantage of middleware?

A: Orchard is built directly atop ASP.NET and not OWIN, so no. If it were, it would be able take advantage.


Q: What frameworks are built on top of OWIN?

A: Currently Nancy is the only one. Frank is coming. Others could be built on top. Fubu? OpenRasta?


Q: Isn't ASP.NET a framework?

A: Yes, in part. But it also allows programmability access into IIS. They are tightly bound together. If you are tied to ASP.NET, you wouldn't be able to take advantage of an abstraction layer.

A: It is possible to split ASP.NET into framework only and run that on top of OWIN. For OWIN, thus far, it's only been discussed, but some have done it in the past. Mono's implementation is an example.


Lifecycle of an Application

Gate - the OWIN core functionality. (You are welcome to build your own.)

Gate Builder provides a declarative way to configure an application to run on a host server.


class Startup {

    void Configuration(AppBuilder builder) {









Comments (0)

You don't have permission to comment on this page.