Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Hosting a Custom Host Console Application with Owin/Katana

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 879
    Comment on it

    OWIN and KATANA

    Imagine that you are writing a framework to web developers, a framework like asp.net MVC. One decision you have to make is this, how you are going to interact with infrastructure behind you which is a Web server. That's the process that would host the framework to coordinate with operating system to listen for HTTP request on a socket. How would your software interact with that host? Over a decade now asp.net framework including Asp.net MVC has build on the top of "Internet Information Services" which provides the hosting and infrastructure features and has been around longer than the asp.net.
    ASP.net run-time and IIS both over the years provide a wonderful collection and features(caching, authentication, compression and inscription) and even if you look in specific features like diagnostic you find at least four different approaches
    1) logging
    2) request monitoring
    3) tracing
    4) and others
    But not everyone needs these features. And over the last few years we began to see a bit of a shift the architecture of the web applications as html5 standards continue to mature, we see more processing is happening on client side. So instead of using heavy processing on server to generate html, the server is only responding asynchronous ajax request to sending back all data for client to process.
    This is also true when you are building mobile services which is consumed by native mobile app and of course mobile app exploded an popularity over last five years. So some teams are looking for today is a fast and light weight and extensible host for web application in web services. Particularly with cloud based services where you pay for every byte and CPU cycle. So you can save the money. you can see this in the world of node.js. Not node is the web server itself but it's easy to add a package, single library to node and make it a web server. A web server that has exactly the features that you need to build in application nothing extra. And that means the server is fast, efficient and easier to scale. And that's one of the Goal of KATANA.
    To provide light weight peace of software that you can use to build web applications, web sites and web APIs. KATANA can still include the features that you need for the web. With Asp.net MVC we use the system.web assembly in every project. System.web is the core of the asp.net and it includes everything from caching to configuration to web socket. But instead of one large assembly OWIN features are highly modular and componentiesed. So you can use only the features you need for a project and that's. One goal of katana is to be as light weight as possible and another goal is to enable modular software. To do that KATANA is actually build on a specifications called OWIN. KATANA is Microsoft's implementation on open standards named OWIN which stands for Open Web Interface for .Net. OWIN was started by group of open source developers in the community who wanted to find an API for web service and web framework to interact.
    The idea was to provide simple specification to make this an easy API because the ultimate goal is for web framework and web service remain decouple. Someone who writes a framework or component doesn't need to worry whether running in asp.net IIS or running at the someone's custom desktop application that also want to reply on HTTP messages. OWIN is a specification it define an API for frameworks and service to cooperate.

    To create a demo app follow the steps
    1) Open visual studio, select template windows desktop and select a console application project type.
    2) Open package manager console from right top search(quick launch 'ctr+Q') of the the VS and install the below 2 packages for owin:
    a) install-package -IncludePrerelease Microsoft.owin.hosting
    b) install-package -IncludePrerelease Microsoft.owin.Host.HttpListener
    3) now write this code patch in main method


     static void Main(string[] args)
            {
                string uri = "http://localhost:8080";
                using (WebApp.Start<Startup>(uri))
                {
                    Console.WriteLine("Server Started!");
                    Console.ReadKey();
                    Console.WriteLine("Stopping!");
                }
            }
    

    4) and create a class like below

    public class Startup
            {
                public void Configuration(IAppBuilder app)
                { 
                    app.Run(ctx =>
                    {
                      return ctx.Response.WriteAsync("Hello katan world!");  
                    });
                }
            }
    

    And now run the application. Then hit the url mentioned above(http://localhost:8080)

    for more detail visit http://www.asp.net/aspnet/overview/owin-and-katana

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: