SlideShare a Scribd company logo
1 of 38
NoIIS
OWIN, KATANA BY MICROSOFT
Bilal Haidar, http://blog.bilalhaidar.com
NOT ONLY IIS
AGENDA
• Microsoft Web Platform, Brief History
• OWIN is a Specification
• Katana by Microsoft
ASP.NET: BRIEF HISTORY
 ASP.NET first released in early 2002 with the .NET
Framework 1.0
 Optimized for 2 primary customers:
 Classic ASP developers
 Desktop LOB developers
THIS CREATED SOME
CHALLENGES…
 ASP.NET shipped as a part of .NET Framework – slow ship
cycle (time between releases was on the order of years)
 As the ASP.NET requirements grew, so did the size &
complexity of System.Web
 All of the features were turned on by default – you have to
opt out
 Only one hosting option – IIS
REVOLUTIONARY STEPS…
 2007-2008: ASP.NET MVC ships out of band from the .NET
Framework
 Enables more rapid ship cycle
 Open Source!
 Still tied to System.Web 
TOWARDS MODERN WEB
APPS…
“Shift from dynamic, server-generated Web pages to static initial markup
with dynamic sections of the page generated from client-side script
communicating with backend Web APIs through AJAX requests”
 2012: ASP.NET Web API released, NUGET package
 Designed with no dependencies on System.Web
 No dependency on System.Web 
 Includes self-hosting capability (NoIIS)
THE SELF-HOST
REALIZATION…
“The power and flexibility of Web API’s self-hosting capability proved
very attractive to developers who wanted a small, lightweight host of their
services”
 ASP.NET Web API enabled self-hosting
 Other frameworks had or were writing their own self-host
servers (e.g. SignalR)
“A modern Web application generally supports static file serving,
dynamic page generation, Web API, and SignalR.”
WHAT’S NEEDED?
“What was needed was a single hosting abstraction that would enable a
developer to compose an application from a variety of different
components and frameworks, and then run that application on a
supporting host.”
Welcome to OWIN
Open Web Interface for .NET
OWIN
“A specification aiming at creating abstraction between Web servers
and framework components” (http://www.owin.org)
• Inspired by the benefits achieved by Rack & Nodejs
• 2 Microsoft employee behind it (Benjamin Vanderveen & Louis
Dejardin)
• 2 main goals:
• New components could be more easily developed &
consumed
• Apps could be more easily ported between hosts &
potentially entire platforms/OS.
OWIN CORE ELEMENTS
• Environment dictionary
• Application Delegate
OWIN ENVIRONMENT
DICTIONARY
• A data structure: IDictionary<string, object>
• Stores all of the state necessary for processing an HTTP
request & response
“An OWIN-compatible Web server is responsible for populating the
environment dictionary with data such as the body streams and header
collections for an HTTP request and response. It is then the responsibility
of the application or framework components to populate or update the
dictionary values and write to the response body stream”
OWIN ENVIRONMENT
DICTIONARY
Required Key Name Value Description
Yes "owin.RequestBody" A Stream with the request body, if any.
Yes "owin.RequestHeaders" An IDictionary<string, string[]> of request headers.
Yes "owin.RequestMethod"
A string containing the HTTP request method of the request
(e.g., "GET", "POST").
Yes "owin.RequestPath"
A string containing the request path. The path MUST be relative to the "root" of
the application delegate.
Yes "owin.RequestPathBase"
A string containing the portion of the request path corresponding to the "root" of
the application delegate.
Yes "owin.RequestProtocol"
A string containing the protocol name and version
(e.g. "HTTP/1.0" or "HTTP/1.1").
Yes "owin.RequestQueryString"
A string containing the query string component of the HTTP request URI, without
the leading “?” (e.g., "foo=bar&baz=quux"). The value may be an empty string.
Yes "owin.RequestScheme" A string containing the URI scheme used for the request (e.g., "http", "https").
OWIN ENVIRONMENT
DICTIONARY
Required Key Name Value Description
Yes "owin.ResponseBody" A Stream used to write out the response body, if any
Yes "owin.ResponseHeaders" An IDictionary<string, string[]> of response headers.
No "owin.ResponseStatusCode"
An optional int containing the HTTP response status code as defined in RFC
2616 section 6.1.1. The default is 200.
No "owin.ResponseReasonPhrase"
An optional string containing the reason phrase associated the given status
code. If none is provided then the server SHOULD provide a default as described
in RFC 2616section 6.1.1
No "owin.ResponseProtocol"
An optional string containing the protocol name and version
(e.g. "HTTP/1.0" or "HTTP/1.1"). If none is provided then
the “owin.RequestProtocol” key’s value is the default.
Yes "owin.ResponseBody" A Stream used to write out the response body, if any.
Yes "owin.ResponseHeaders" An IDictionary<string, string[]> of response headers.
No "owin.ResponseStatusCode"
An optional int containing the HTTP response status code as defined in RFC
2616 section 6.1.1. The default is 200.
OWIN APPLICATION
DELEGATE
“The primary interface in OWIN is called the application delegate or
AppFunc.
An application delegate takes the IDictionary<string, object> environment
variable and returns a Task when it has finished processing.”
using AppFunc =
Func<IDictionary<string, object>, Task>;
OWIN APPLICATION
DELEGATE
“The application delegate is an implementation of the Func delegate type
where the function accepts the environment dictionary as input and
returns a task.”
“The asynchronous design enables the abstraction to be efficient with its
handling of computing resources, particularly in more I/O intensive
operations.”
“Because the application delegate is an atomic unit of execution and
because the environment dictionary is carried as a parameter on the
delegate, OWIN components could be easily chained together to create
complex HTTP processing pipelines.”
KATANA
 Microsoft’s OWIN implementation
 https://katanaproject.codeplex.com/
 Set of hosts and servers
 IIS or self-host
 Set of convenience classes
 OwinContext, OwinRequest, OwinResponse, etc.
 AppBuilderUseExtensions
 AuthenticationManager
 Set of middleware for common features
 Authentication
 Hosting content (e.g. static files)
 CORS
KATANA WEB STACK
 Host manages process lifetime (start & stop), it could be IIS or any other custom/standalone
executable.
 Server listens for HTTP requests, constructs the environment dictionary, Startups the application &
processes requests through an OWIN pipeline.
 Middleware are specific components that runs in the OWIN pipeline (e.g. WebAPI, SignalR, etc.). A
middleware is simply a component that exposes the application delegate.
 Application is the code you write!
client
Host
OWIN Server
Middleware Middleware Application
KATANA COMPONENTS
Host
Server
Middleware
Application
• IIS
• OwinHost.exe (OwinHost)
• Custom Process (e.g. Console app, Windows
Service)
• SystemWeb (Microsoft.Owin.Host.SystemWeb)
• HttpListener (Microsoft.Owin.Host.HttpListener)
• SignalR)
• Web API
• Nancy (MVC Framework)
• etc.
KATANA NUGET PACKAGES
 Self Hosting / No IIS
 IIS Hosting
PM> Install-Package Microsoft.Owin.SelfHost
Attempting to resolve dependency 'Owin (≥ 1.0)'.
Attempting to resolve dependency 'Microsoft.Owin (≥ 2.1.0)'.
Attempting to resolve dependency 'Microsoft.Owin.Diagnostics (≥
2.1.0)'.
PM> Install-Package Microsoft.Owin.Host.SystemWeb
Attempting to resolve dependency 'Owin (≥ 1.0)'.
Attempting to resolve dependency 'Microsoft.Owin (≥ 2.1.0)'.
KATANA NUGET PACKAGES
 OwinHost / No IIS
PM> Install-Package OwinHost
PM> Install-Package Microsoft.Owin
Attempting to resolve dependency 'Owin (≥ 1.0)'.
KATANA STARTUP
 Startup class
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(IISHosting.Startup))]
namespace IISHosting
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseHandlerAsync((req, res) => {
res.ContentType = "text/plain";
return res.WriteAsync("Hello Katana!");
});
}
}
}
KATANA STARTUP
DETECTION
 Naming Convention: Katana looks for a class named Startup in
namespace matching the assembly name
 OwinStartup Attribute: Katana looks for the OwinStartup attribute to
locate the Startup class. The OwinStartup attribute overrides the naming
convention
 appSetting element in the Configuration file:
The appSetting element overrides the OwinStartup attribute
and naming convention
[assembly: OwinStartup(typeof(StartupDemo.TestStartup))]
<appSettings>
<add key="owin:appStartup" value="StartupDemo.TestStartup" />
</appSettings>
KATANA HOST
(CUSTOM PROCESS)
using System;
using Microsoft.Owin.Hosting;
namespace NoIISHosting
{
public class Program
{
static void Main(string[] args)
{
var baseUrl = "http://localhost:5000";
if (args[0] == "--url") { baseUrl = args[1]; }
using (WebApp.Start<Startup>(new StartOptions(baseUrl) { ServerFactory =
"Microsoft.Owin.Host.HttpListener"}))
{
Console.WriteLine(string.Format("Katana Server running @ {0}", baseUrl));
Console.WriteLine();
// Keep the server going until we're done
Console.WriteLine("Press [Enter] To Exit ...");
Console.ReadKey();
}
}
}
}
Starting SERVER
(HttpListener) & using
Startup
KATANA MIDDLEWARE
 Code to process requests
 A class with a constructor accepting:
 Func<IDictionary<string, object>, Task> (aka “AppFunc”)
representing the NEXT middleware in the pipeline
 Method named Invoke (by convention) accepting as input
IDictionary<string, object>
 One or more Middlewares can be chained in a pipeline
KATANA CONFIGURING
MIDDLEWARE
public class Startup
{
public void Configuration (IAppBuidler app)
{
app.Use(typeof(SomeMiddleware));
}
}
KATANA MIDDLEWARE
using AppFunc = Func<IDictionary<string, object>, Task>;
public class SimpleLogger
{
private readonly AppFunc _next;
private readonly SimpleLoggerOptions _options;
public SimpleLogger(AppFunc next, SimpleLoggerOptions options)
{
_next = next;
_options = options;
}
public async Task Invoke(IDictionary<string, object> environment)
{
foreach (var key in _options.RequestKeys)
{
_options.Log(key, environment[key]);
}
await _next(environment);
foreach (var key in _options.ResponseKeys)
{
_options.Log(key, environment[key]);
}
}
}
public class SimpleLoggerOptions
{
public IList<string> RequestKeys { get; set; }
public IList<string> ResponseKeys { get; set; }
public Action<string, object> Log { get; set; }
}
Request Processing
Response Processing
NEXT Middleware in
Pipeline
AppFunc
KATANA OWINCONTEXT
 An API providing a strongly typed wrapper for
environment dictionary
public async Task Invoke(IDictionary<string, object> env)
{
var ctx = new OwinContext(env);
var url = ctx.Request.Uri;
var accept = ctx.Request.Headers["Accept"];
var username = ctx.Request.User.Identity.Name;
ctx.Response.StatusCode = 200;
ctx.Response.Headers.Add("Myheader", new [] {"cusotm value"});
using (var sw = new StreamWriter(ctx.Response.Body))
{
await sw.WriteLineAsync("<h1>Hello Katana!</h1>");
}
}
SIGNALR 2.0 SELF HOSTING
 Console App hosting the server & configuring signalR in
OWIN pipeline
 Empty Website hosting signalR JS files & HTML
 Start by:
 Create Console App & install Nuget Packages:
PM> Install-Package Microsoft.AspNet.SignalR.SelfHost
PM> Install-Package Microsoft.Owin.Cors
SIGNALR 2.0 SELF HOSTING
 Add Program class to host the HttpListener server
using System;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Hosting;
using Owin;
using Microsoft.Owin.Cors;
namespace SignalRSelfHost
{
public class Program
{
static void Main(string[] args)
{
var url = "http://localhost:8080";
using (WebApp.Start(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
}
}
SIGNALR 2.0 SELF HOSTING
 Add Startup class to configure & add SignalR to OWIN
pipeline
using System;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Hosting;
using Owin;
using Microsoft.Owin.Cors;
namespace SignalRSelfHost
{
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
}
SIGNALR 2.0 SELF HOSTING
 Add MyHub class to communicate with clients connecting
to SignalR server
using System;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Hosting;
using Owin;
using Microsoft.Owin.Cors;
namespace SignalRSelfHost
{
public class MyHub : Hub
{
public void Send(string name, string message)
{
Clients.All.addMessage(name, message);
}
}
}
Defined by Server,
Called by Client
Defined by Client,
Called by Server
SIGNALR 2.0 SELF HOSTING
 Add Empty Website to host SignalR JS files & HTML
page
 Install the following Nuget Packages:
 Finally, add an HTML page
PM> Install-Package Microsoft.AspNet.SignalR.JS
SIGNALR 2.0 SELF HOSTING
<script type="text/javascript">
$(function () {
//Set the hubs URL for the connection
$.connection.hub.url = "http://localhost:8080/signalr";
// Declare a proxy to reference the hub.
var chat = $.connection.myHub;
// Create a function that the hub can call to broadcast messages.
chat.client.addMessage = function (name, message) {
// Html encode display name and message.
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
// Add the message to the page.
$('#discussion').append('<li><strong>' + encodedName
+ '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
</script>
KATANA GOALS
 Composability
 Portability
 Performance & Scalability
Server Starts
Your app’s
startup
Auth
Static
files
Web
API
KATANA PORTABILITY
IIS
SystemWeb
Web API + SignalR + static files
Application
Windows (local or remote)
Console App / Owin Host
HttpListener
Web API + SignalR + static files
Application
Windows (local or remote)
OwinHost
HttpSys
Web API + SignalR + static files
Application
Windows Azure Worker Role
KATANA PERF / SCALE
 Composition model gives you control over performance
characteristics
 Async throughout
 Separate server and host components
REFERENCES
 Open Web Interface for .NET
 OWIN & Katana
 Mini-Training OWIN & Katana
 The Katana Project
 Getting Started with the Katana Project
 OWIN and Katana (The new HTTP Host for Web Apps)

More Related Content

What's hot

What's hot (20)

Owin & katana
Owin & katanaOwin & katana
Owin & katana
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0
 
Powershell For Developers
Powershell For DevelopersPowershell For Developers
Powershell For Developers
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platformIntroducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
 
Debugging your Way through .NET with Visual Studio 2015
Debugging your Way through .NET with Visual Studio 2015Debugging your Way through .NET with Visual Studio 2015
Debugging your Way through .NET with Visual Studio 2015
 
Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6
 
O que é esse tal de OWIN?
O que é esse tal de OWIN?O que é esse tal de OWIN?
O que é esse tal de OWIN?
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introduction
 
Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...
Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...
Microservices Platform with Spring Boot, Spring Cloud Config, Spring Cloud Ne...
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Integrating Apache Syncope with Apache CXF
Integrating Apache Syncope with Apache CXFIntegrating Apache Syncope with Apache CXF
Integrating Apache Syncope with Apache CXF
 
CXF 3.0, What's new?
CXF 3.0, What's new?CXF 3.0, What's new?
CXF 3.0, What's new?
 

Viewers also liked

Viewers also liked (8)

Real-Time Web Applications with ASP.NET WebAPI and SignalR
Real-Time Web Applications with ASP.NET WebAPI and SignalRReal-Time Web Applications with ASP.NET WebAPI and SignalR
Real-Time Web Applications with ASP.NET WebAPI and SignalR
 
DevIntersections 2014 Web API Slides
DevIntersections 2014 Web API SlidesDevIntersections 2014 Web API Slides
DevIntersections 2014 Web API Slides
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi Applications
 
Micro Services in .NET Core and Docker
Micro Services in .NET Core and DockerMicro Services in .NET Core and Docker
Micro Services in .NET Core and Docker
 
How to Make Own Framework built on OWIN
How to Make Own Framework built on OWINHow to Make Own Framework built on OWIN
How to Make Own Framework built on OWIN
 
web apiで遊び倒す
web apiで遊び倒すweb apiで遊び倒す
web apiで遊び倒す
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural Comparison
 
Web 2.0 Business Models
Web 2.0 Business ModelsWeb 2.0 Business Models
Web 2.0 Business Models
 

Similar to OWIN and Katana Project - Not Only IIS - NoIIS

Scalable Web Architectures and Infrastructure
Scalable Web Architectures and InfrastructureScalable Web Architectures and Infrastructure
Scalable Web Architectures and Infrastructure
george.james
 
Managing Docker & ECS Based Applications with AWS Elastic Beanstalk - DevDay ...
Managing Docker & ECS Based Applications with AWS Elastic Beanstalk - DevDay ...Managing Docker & ECS Based Applications with AWS Elastic Beanstalk - DevDay ...
Managing Docker & ECS Based Applications with AWS Elastic Beanstalk - DevDay ...
Amazon Web Services
 

Similar to OWIN and Katana Project - Not Only IIS - NoIIS (20)

ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
AWS Elastic Beanstalk - Running Microservices and Docker
AWS Elastic Beanstalk - Running Microservices and DockerAWS Elastic Beanstalk - Running Microservices and Docker
AWS Elastic Beanstalk - Running Microservices and Docker
 
Elastic beanstalk
Elastic beanstalkElastic beanstalk
Elastic beanstalk
 
Running Microservices on AWS Elastic Beanstalk
Running Microservices on AWS Elastic BeanstalkRunning Microservices on AWS Elastic Beanstalk
Running Microservices on AWS Elastic Beanstalk
 
Running Microservices and Docker on AWS Elastic Beanstalk - August 2016 Month...
Running Microservices and Docker on AWS Elastic Beanstalk - August 2016 Month...Running Microservices and Docker on AWS Elastic Beanstalk - August 2016 Month...
Running Microservices and Docker on AWS Elastic Beanstalk - August 2016 Month...
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Scalable Web Architectures and Infrastructure
Scalable Web Architectures and InfrastructureScalable Web Architectures and Infrastructure
Scalable Web Architectures and Infrastructure
 
Philly Tech Fest Iis
Philly Tech Fest IisPhilly Tech Fest Iis
Philly Tech Fest Iis
 
Managing Docker & ECS Based Applications with AWS Elastic Beanstalk - DevDay ...
Managing Docker & ECS Based Applications with AWS Elastic Beanstalk - DevDay ...Managing Docker & ECS Based Applications with AWS Elastic Beanstalk - DevDay ...
Managing Docker & ECS Based Applications with AWS Elastic Beanstalk - DevDay ...
 
Deploy, Manage, and Scale your Apps with AWS Elastic Beanstalk
Deploy, Manage, and Scale your Apps with AWS Elastic BeanstalkDeploy, Manage, and Scale your Apps with AWS Elastic Beanstalk
Deploy, Manage, and Scale your Apps with AWS Elastic Beanstalk
 
ASP.NET vNext
ASP.NET vNextASP.NET vNext
ASP.NET vNext
 
ASP.NET vNext ANUG 20140817
ASP.NET vNext ANUG 20140817ASP.NET vNext ANUG 20140817
ASP.NET vNext ANUG 20140817
 
AWS Elastic Beanstalk運作微服務與Docker
AWS Elastic Beanstalk運作微服務與Docker AWS Elastic Beanstalk運作微服務與Docker
AWS Elastic Beanstalk運作微服務與Docker
 
OWIN Why should i care?
OWIN Why should i care?OWIN Why should i care?
OWIN Why should i care?
 
DevOps with Elastic Beanstalk - TCCC-2014
DevOps with Elastic Beanstalk - TCCC-2014DevOps with Elastic Beanstalk - TCCC-2014
DevOps with Elastic Beanstalk - TCCC-2014
 
Aws elastic beanstalk
Aws elastic beanstalkAws elastic beanstalk
Aws elastic beanstalk
 
AWS re:Invent 2016: Infrastructure Continuous Delivery Using AWS CloudFormati...
AWS re:Invent 2016: Infrastructure Continuous Delivery Using AWS CloudFormati...AWS re:Invent 2016: Infrastructure Continuous Delivery Using AWS CloudFormati...
AWS re:Invent 2016: Infrastructure Continuous Delivery Using AWS CloudFormati...
 
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
 
AWS Elastic Beanstalk: Running Multi-Container Docker Applications - DevDay L...
AWS Elastic Beanstalk: Running Multi-Container Docker Applications - DevDay L...AWS Elastic Beanstalk: Running Multi-Container Docker Applications - DevDay L...
AWS Elastic Beanstalk: Running Multi-Container Docker Applications - DevDay L...
 

Recently uploaded

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

OWIN and Katana Project - Not Only IIS - NoIIS

  • 1. NoIIS OWIN, KATANA BY MICROSOFT Bilal Haidar, http://blog.bilalhaidar.com NOT ONLY IIS
  • 2. AGENDA • Microsoft Web Platform, Brief History • OWIN is a Specification • Katana by Microsoft
  • 3. ASP.NET: BRIEF HISTORY  ASP.NET first released in early 2002 with the .NET Framework 1.0  Optimized for 2 primary customers:  Classic ASP developers  Desktop LOB developers
  • 4. THIS CREATED SOME CHALLENGES…  ASP.NET shipped as a part of .NET Framework – slow ship cycle (time between releases was on the order of years)  As the ASP.NET requirements grew, so did the size & complexity of System.Web  All of the features were turned on by default – you have to opt out  Only one hosting option – IIS
  • 5. REVOLUTIONARY STEPS…  2007-2008: ASP.NET MVC ships out of band from the .NET Framework  Enables more rapid ship cycle  Open Source!  Still tied to System.Web 
  • 6. TOWARDS MODERN WEB APPS… “Shift from dynamic, server-generated Web pages to static initial markup with dynamic sections of the page generated from client-side script communicating with backend Web APIs through AJAX requests”  2012: ASP.NET Web API released, NUGET package  Designed with no dependencies on System.Web  No dependency on System.Web   Includes self-hosting capability (NoIIS)
  • 7. THE SELF-HOST REALIZATION… “The power and flexibility of Web API’s self-hosting capability proved very attractive to developers who wanted a small, lightweight host of their services”  ASP.NET Web API enabled self-hosting  Other frameworks had or were writing their own self-host servers (e.g. SignalR) “A modern Web application generally supports static file serving, dynamic page generation, Web API, and SignalR.”
  • 8. WHAT’S NEEDED? “What was needed was a single hosting abstraction that would enable a developer to compose an application from a variety of different components and frameworks, and then run that application on a supporting host.” Welcome to OWIN Open Web Interface for .NET
  • 9. OWIN “A specification aiming at creating abstraction between Web servers and framework components” (http://www.owin.org) • Inspired by the benefits achieved by Rack & Nodejs • 2 Microsoft employee behind it (Benjamin Vanderveen & Louis Dejardin) • 2 main goals: • New components could be more easily developed & consumed • Apps could be more easily ported between hosts & potentially entire platforms/OS.
  • 10. OWIN CORE ELEMENTS • Environment dictionary • Application Delegate
  • 11. OWIN ENVIRONMENT DICTIONARY • A data structure: IDictionary<string, object> • Stores all of the state necessary for processing an HTTP request & response “An OWIN-compatible Web server is responsible for populating the environment dictionary with data such as the body streams and header collections for an HTTP request and response. It is then the responsibility of the application or framework components to populate or update the dictionary values and write to the response body stream”
  • 12. OWIN ENVIRONMENT DICTIONARY Required Key Name Value Description Yes "owin.RequestBody" A Stream with the request body, if any. Yes "owin.RequestHeaders" An IDictionary<string, string[]> of request headers. Yes "owin.RequestMethod" A string containing the HTTP request method of the request (e.g., "GET", "POST"). Yes "owin.RequestPath" A string containing the request path. The path MUST be relative to the "root" of the application delegate. Yes "owin.RequestPathBase" A string containing the portion of the request path corresponding to the "root" of the application delegate. Yes "owin.RequestProtocol" A string containing the protocol name and version (e.g. "HTTP/1.0" or "HTTP/1.1"). Yes "owin.RequestQueryString" A string containing the query string component of the HTTP request URI, without the leading “?” (e.g., "foo=bar&baz=quux"). The value may be an empty string. Yes "owin.RequestScheme" A string containing the URI scheme used for the request (e.g., "http", "https").
  • 13. OWIN ENVIRONMENT DICTIONARY Required Key Name Value Description Yes "owin.ResponseBody" A Stream used to write out the response body, if any Yes "owin.ResponseHeaders" An IDictionary<string, string[]> of response headers. No "owin.ResponseStatusCode" An optional int containing the HTTP response status code as defined in RFC 2616 section 6.1.1. The default is 200. No "owin.ResponseReasonPhrase" An optional string containing the reason phrase associated the given status code. If none is provided then the server SHOULD provide a default as described in RFC 2616section 6.1.1 No "owin.ResponseProtocol" An optional string containing the protocol name and version (e.g. "HTTP/1.0" or "HTTP/1.1"). If none is provided then the “owin.RequestProtocol” key’s value is the default. Yes "owin.ResponseBody" A Stream used to write out the response body, if any. Yes "owin.ResponseHeaders" An IDictionary<string, string[]> of response headers. No "owin.ResponseStatusCode" An optional int containing the HTTP response status code as defined in RFC 2616 section 6.1.1. The default is 200.
  • 14. OWIN APPLICATION DELEGATE “The primary interface in OWIN is called the application delegate or AppFunc. An application delegate takes the IDictionary<string, object> environment variable and returns a Task when it has finished processing.” using AppFunc = Func<IDictionary<string, object>, Task>;
  • 15. OWIN APPLICATION DELEGATE “The application delegate is an implementation of the Func delegate type where the function accepts the environment dictionary as input and returns a task.” “The asynchronous design enables the abstraction to be efficient with its handling of computing resources, particularly in more I/O intensive operations.” “Because the application delegate is an atomic unit of execution and because the environment dictionary is carried as a parameter on the delegate, OWIN components could be easily chained together to create complex HTTP processing pipelines.”
  • 16. KATANA  Microsoft’s OWIN implementation  https://katanaproject.codeplex.com/  Set of hosts and servers  IIS or self-host  Set of convenience classes  OwinContext, OwinRequest, OwinResponse, etc.  AppBuilderUseExtensions  AuthenticationManager  Set of middleware for common features  Authentication  Hosting content (e.g. static files)  CORS
  • 17. KATANA WEB STACK  Host manages process lifetime (start & stop), it could be IIS or any other custom/standalone executable.  Server listens for HTTP requests, constructs the environment dictionary, Startups the application & processes requests through an OWIN pipeline.  Middleware are specific components that runs in the OWIN pipeline (e.g. WebAPI, SignalR, etc.). A middleware is simply a component that exposes the application delegate.  Application is the code you write! client Host OWIN Server Middleware Middleware Application
  • 18. KATANA COMPONENTS Host Server Middleware Application • IIS • OwinHost.exe (OwinHost) • Custom Process (e.g. Console app, Windows Service) • SystemWeb (Microsoft.Owin.Host.SystemWeb) • HttpListener (Microsoft.Owin.Host.HttpListener) • SignalR) • Web API • Nancy (MVC Framework) • etc.
  • 19. KATANA NUGET PACKAGES  Self Hosting / No IIS  IIS Hosting PM> Install-Package Microsoft.Owin.SelfHost Attempting to resolve dependency 'Owin (≥ 1.0)'. Attempting to resolve dependency 'Microsoft.Owin (≥ 2.1.0)'. Attempting to resolve dependency 'Microsoft.Owin.Diagnostics (≥ 2.1.0)'. PM> Install-Package Microsoft.Owin.Host.SystemWeb Attempting to resolve dependency 'Owin (≥ 1.0)'. Attempting to resolve dependency 'Microsoft.Owin (≥ 2.1.0)'.
  • 20. KATANA NUGET PACKAGES  OwinHost / No IIS PM> Install-Package OwinHost PM> Install-Package Microsoft.Owin Attempting to resolve dependency 'Owin (≥ 1.0)'.
  • 21. KATANA STARTUP  Startup class using Microsoft.Owin; using Owin; [assembly: OwinStartup(typeof(IISHosting.Startup))] namespace IISHosting { public class Startup { public void Configuration(IAppBuilder app) { app.UseHandlerAsync((req, res) => { res.ContentType = "text/plain"; return res.WriteAsync("Hello Katana!"); }); } } }
  • 22. KATANA STARTUP DETECTION  Naming Convention: Katana looks for a class named Startup in namespace matching the assembly name  OwinStartup Attribute: Katana looks for the OwinStartup attribute to locate the Startup class. The OwinStartup attribute overrides the naming convention  appSetting element in the Configuration file: The appSetting element overrides the OwinStartup attribute and naming convention [assembly: OwinStartup(typeof(StartupDemo.TestStartup))] <appSettings> <add key="owin:appStartup" value="StartupDemo.TestStartup" /> </appSettings>
  • 23. KATANA HOST (CUSTOM PROCESS) using System; using Microsoft.Owin.Hosting; namespace NoIISHosting { public class Program { static void Main(string[] args) { var baseUrl = "http://localhost:5000"; if (args[0] == "--url") { baseUrl = args[1]; } using (WebApp.Start<Startup>(new StartOptions(baseUrl) { ServerFactory = "Microsoft.Owin.Host.HttpListener"})) { Console.WriteLine(string.Format("Katana Server running @ {0}", baseUrl)); Console.WriteLine(); // Keep the server going until we're done Console.WriteLine("Press [Enter] To Exit ..."); Console.ReadKey(); } } } } Starting SERVER (HttpListener) & using Startup
  • 24. KATANA MIDDLEWARE  Code to process requests  A class with a constructor accepting:  Func<IDictionary<string, object>, Task> (aka “AppFunc”) representing the NEXT middleware in the pipeline  Method named Invoke (by convention) accepting as input IDictionary<string, object>  One or more Middlewares can be chained in a pipeline
  • 25. KATANA CONFIGURING MIDDLEWARE public class Startup { public void Configuration (IAppBuidler app) { app.Use(typeof(SomeMiddleware)); } }
  • 26. KATANA MIDDLEWARE using AppFunc = Func<IDictionary<string, object>, Task>; public class SimpleLogger { private readonly AppFunc _next; private readonly SimpleLoggerOptions _options; public SimpleLogger(AppFunc next, SimpleLoggerOptions options) { _next = next; _options = options; } public async Task Invoke(IDictionary<string, object> environment) { foreach (var key in _options.RequestKeys) { _options.Log(key, environment[key]); } await _next(environment); foreach (var key in _options.ResponseKeys) { _options.Log(key, environment[key]); } } } public class SimpleLoggerOptions { public IList<string> RequestKeys { get; set; } public IList<string> ResponseKeys { get; set; } public Action<string, object> Log { get; set; } } Request Processing Response Processing NEXT Middleware in Pipeline AppFunc
  • 27. KATANA OWINCONTEXT  An API providing a strongly typed wrapper for environment dictionary public async Task Invoke(IDictionary<string, object> env) { var ctx = new OwinContext(env); var url = ctx.Request.Uri; var accept = ctx.Request.Headers["Accept"]; var username = ctx.Request.User.Identity.Name; ctx.Response.StatusCode = 200; ctx.Response.Headers.Add("Myheader", new [] {"cusotm value"}); using (var sw = new StreamWriter(ctx.Response.Body)) { await sw.WriteLineAsync("<h1>Hello Katana!</h1>"); } }
  • 28. SIGNALR 2.0 SELF HOSTING  Console App hosting the server & configuring signalR in OWIN pipeline  Empty Website hosting signalR JS files & HTML  Start by:  Create Console App & install Nuget Packages: PM> Install-Package Microsoft.AspNet.SignalR.SelfHost PM> Install-Package Microsoft.Owin.Cors
  • 29. SIGNALR 2.0 SELF HOSTING  Add Program class to host the HttpListener server using System; using Microsoft.AspNet.SignalR; using Microsoft.Owin.Hosting; using Owin; using Microsoft.Owin.Cors; namespace SignalRSelfHost { public class Program { static void Main(string[] args) { var url = "http://localhost:8080"; using (WebApp.Start(url)) { Console.WriteLine("Server running on {0}", url); Console.ReadLine(); } } } }
  • 30. SIGNALR 2.0 SELF HOSTING  Add Startup class to configure & add SignalR to OWIN pipeline using System; using Microsoft.AspNet.SignalR; using Microsoft.Owin.Hosting; using Owin; using Microsoft.Owin.Cors; namespace SignalRSelfHost { class Startup { public void Configuration(IAppBuilder app) { app.UseCors(CorsOptions.AllowAll); app.MapSignalR(); } } }
  • 31. SIGNALR 2.0 SELF HOSTING  Add MyHub class to communicate with clients connecting to SignalR server using System; using Microsoft.AspNet.SignalR; using Microsoft.Owin.Hosting; using Owin; using Microsoft.Owin.Cors; namespace SignalRSelfHost { public class MyHub : Hub { public void Send(string name, string message) { Clients.All.addMessage(name, message); } } } Defined by Server, Called by Client Defined by Client, Called by Server
  • 32. SIGNALR 2.0 SELF HOSTING  Add Empty Website to host SignalR JS files & HTML page  Install the following Nuget Packages:  Finally, add an HTML page PM> Install-Package Microsoft.AspNet.SignalR.JS
  • 33. SIGNALR 2.0 SELF HOSTING <script type="text/javascript"> $(function () { //Set the hubs URL for the connection $.connection.hub.url = "http://localhost:8080/signalr"; // Declare a proxy to reference the hub. var chat = $.connection.myHub; // Create a function that the hub can call to broadcast messages. chat.client.addMessage = function (name, message) { // Html encode display name and message. var encodedName = $('<div />').text(name).html(); var encodedMsg = $('<div />').text(message).html(); // Add the message to the page. $('#discussion').append('<li><strong>' + encodedName + '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>'); }; // Get the user name and store it to prepend to messages. $('#displayname').val(prompt('Enter your name:', '')); // Set initial focus to message input box. $('#message').focus(); // Start the connection. $.connection.hub.start().done(function () { $('#sendmessage').click(function () { // Call the Send method on the hub. chat.server.send($('#displayname').val(), $('#message').val()); // Clear text box and reset focus for next comment. $('#message').val('').focus(); }); }); }); </script>
  • 34. KATANA GOALS  Composability  Portability  Performance & Scalability
  • 36. KATANA PORTABILITY IIS SystemWeb Web API + SignalR + static files Application Windows (local or remote) Console App / Owin Host HttpListener Web API + SignalR + static files Application Windows (local or remote) OwinHost HttpSys Web API + SignalR + static files Application Windows Azure Worker Role
  • 37. KATANA PERF / SCALE  Composition model gives you control over performance characteristics  Async throughout  Separate server and host components
  • 38. REFERENCES  Open Web Interface for .NET  OWIN & Katana  Mini-Training OWIN & Katana  The Katana Project  Getting Started with the Katana Project  OWIN and Katana (The new HTTP Host for Web Apps)