SlideShare a Scribd company logo
OWIN-.NETにおけるPSGI - 
2014/12/13 -#nds39 
TAKANO Sho(高野将)/ @masaru_b_cl
自己紹介 
プログラマー兼業家政夫 
お父さん業も取り扱っております 
CodeZine等で執筆業も 
懐かしのLTSV祭りのときのC#実装”DynamicLTSV”の中の人 http://rebuild.fm/1https://gist.github.com/akiyan/5010610#ltsv--0004526 
#nds39 2
Agenda 
OWINとは? 
OWINの概要 
OWINの実装 
OWINのホスティング 
そしてASP.NET 5へ 
#nds39 3
OWINとは? 
#nds39 4
OWINとは? 
OWIN—Open Web Interface for .NEThttp://owin.org/ 
“OWIN defines a standard interface between.NET web servers and web applications.” 
”OWINは.NET WebサーバーとWebアプリケーション間の 標準インターフェースを定める。” 
#nds39 5
どういうことか? 
旧来の.NET Webアプリケーション構成 
IIS 
.NET Webアプリ 
IIS(Internet Information Service)*と不可分 * Windows Serverに搭載されたWebサーバーコンポーネント 
#nds39 6 
HTTP(S)
どういうことか? 
IISと密に結合していることで…… 
リクエストパイプライン処理などが重い 
ポータブルでない 
Windows以外で動かない 
#nds39 7
OWINでどうなるか? 
OWINのWebアプリケーション構成 
IIS等の 
Webサーバー 
.NET 
Webアプリ 
IISから解放される 
#nds39 8 
OWIN 
HTTP(S)
OWINでどうなるか? 
したがって…… 
Windows 
サービス* 
or コンソール アプリ 
.NET 
Webアプリ 
IIS以外でセルフホストすることもできる 
* POSIX環境でいうdaemon 
#nds39 9 
OWIN 
HTTP(S)
OWINでどうなるか? 
さらに…… 
コンソール アプリ 
.NET 
Webアプリ 
Mac、Linux上のMono*でもホストできる * .NET FrameworkランタイムのOSS実装 
#nds39 10 
OWIN 
HTTP(S) 
Mono 
on 
Mac, Linux
OWINの概要 
#nds39 11
OWINの概要 
OWINは先述の通りインターフェース定義 
つまり、あくまで仕様 
OWIN 1.0 Specificationhttp://owin.org/spec/spec/owin-1.0.0.html 
#nds39 12
OWINの概要 
PerlでいうPSGI、PythonでいうWSGIにあたる 
PSGI -search.cpan.orghttp://search.cpan.org/~miyagawa/PSGI-1.102/PSGI.pod 
WSGI —WSGI.orghttp://wsgi.readthedocs.org 
#nds39 13
OWINの仕様 
OWINでは以下のapplication delegate(AppFunc)にて パイプライン処理を行う 
#nds39 14 
using AppFunc= Func< 
IDictionary<string, object>, // Environment 
Task>; // Done
OWINの仕様 
Enviromment 
型: IDictionary<string, object> 
OWINのパイプラインに必要なすべての情報を格納する ハッシュテーブル 
文字列をキーとして、最も汎用的な型であるobject型で 各情報を持つ 
キーの値はOWINの仕様で定められた他、 独自のキーを使用することもできる 
#nds39 15
OWINの仕様 
Done 
型: Task 
OWINのパイプラインの次の処理を呼び出す非同期動作 
呼び出すことでパイプライン処理を次に進める 
呼び出さなければパイプライン処理を打ち切る 
#nds39 16
OWINの処理イメージ 
AppFuncの一つ一つがOWINミドルウェアと呼ばれる 
OWINミドルウェアではEnvironmentの情報の出し入れを行う 
Doneタスクでコアに向かってパイプラインを進める 
#nds39 17 
“owin.RequestMethod” 
“GET” 
“owin.RequestHeaders 
ハッシュテーブル 
: 
: 
Environment 
AppFunc1 
AppFunc2 
AppFuncCore 
… 
Request 
Response 
Done 
Done
OWINの処理イメージ 
OWINミドルウェアのそれぞれは小さな一つの処理を担当する 
エラーハンドリング、キャッシュ、ルーティング、セッション、etc… 
このミドルウェアを柔軟に組み合わせることで、拡張性に優れた Webアプリケーションを構築する 
WSGIのタマネギのイメージ 
#nds39 18 
※イメージはここから参照 
Concepts of Pylons —Pylons Framework 1.0.1 documentationhttp://docs.pylonsproject.org/projects/pylons- webframework/en/latest/concepts.html#wsgi-middleware
OWINの実装 
#nds39 19
OWINの実装 
OWINは仕様でありその実装が必要 
PSGIにおけるPlack等 
WSGIにおけるPylons等 
Owinのインターフェース定義はOwin.dll 
#nds39 20
OWINの実装 
アプリケーションフレームワークの デファクトスタンダードはKatanaプロジェクト 
その他の実装 
Nowin 
サーバー、ホスト環境 
Freya 
F#実装 
#nds39 21
Katanaプロジェクト 
Microsoftによるリファレンス実装 
Owin.dllをラップするMicrosoft.Owin名前空間 
素のOwin.dllではやはりつらい 
生のキーを使ったダウンキャストの嵐 
Microsoft.Owinを使うことで簡単に実装できる 
型安全 
ミドルウェア基底型 
#nds39 22
コード例(Hello World) 
Plack 
#nds39 23 
my$app = sub{ 
return[ 
200, 
[ 'Content-Type'=> 'text/plain'], 
[ 'Hello World'] 
]; 
}; 
※PlackHandbook | Day 2: Hello World より 
https://github.com/miyagawa/plack-handbook/blob/master/ja%2F02_hello_world.md
コード例(Hello World) 
Microsoft.Owin 
#nds39 24 
publicclassStartup 
{ 
publicvoidConfiguration(IAppBuilderapp) 
{ 
app.Run(asynccontext => 
{ 
varresponse = context.Response; 
response.StatusCode= 200; 
response.ContentType= "text/plain"; 
awaitresponse.WriteAsync("Hello World"); 
}); 
} 
} 
※Getting Started with OWIN and Katana | The ASP.NET Site より 
http://www.asp.net/aspnet/overview/owin-and-katana/getting-started-with-owin-and-katana
コード例(Hello World) 
DEMO 
#nds39 25 
•Hello World
コード例(ミドルウェア) 
Plack 
#nds39 26 
usePlack::Builder; 
my$app = sub{ ... }; 
builder{ 
enable"SomeMiddleware"; 
$app; 
}; 
※PlackHandbook | Day 10: Plackミドルウェアの利用より 
https://github.com/miyagawa/plack-handbook/blob/master/ja%2F10_using_plack_middleware.md
コード例(ミドルウェア) 
Microsoft.Owin 
#nds39 27 
publicclassStartup 
{ 
publicvoidConfiguration(IAppBuilderapp) 
{ 
app.Use(async(context, next) => 
{ 
... 
awaitnext(); 
}); 
app.Run(asynccontext => ...); 
} 
} 
※neuecc -OWINのパイプラインとMiddleware作成ガイドより 
http://neue.cc/2014/01/06_442.html
コード例(ミドルウェア) 
Microsoft.Owin 
#nds39 28 
publicclassStartup 
{ 
publicvoidConfiguration(IAppBuilderapp) 
{ 
... 
app.Use<SomeMiddleware>(someOption); 
app.Run(asynccontext => ...); 
} 
} 
※neuecc -OWINのパイプラインとMiddleware作成ガイドより 
http://neue.cc/2014/01/06_442.html
コード例(ミドルウェア) 
DEMO 
#nds39 29 
•インラインでのミドルウェア記述 
•独立したミドルウェアの使用 
•Basic認証ミドルウェアの使用
OWINのホスティング 
#nds39 30
OWINのホスティング 
IISホスト 
開発IIS Express 
テストIIS 
運用IIS / Azure Web Site 
セルフホスト 
Console App 
Herokuwith Mono 
Windows Service 
#nds39 31
IISホストAzure Web Site 
DEMO 
#nds39 32 
•http://nds39-owin.azurewebsites.net/
セルフホストHerokuwith Mono 
DEMO 
#nds39 33 
•https://nds39-owin.herokuapp.com/
そしてASP.NET 5へ 
#nds39 34
次のASP.NET 
2系統に分かれる 
ASP.NET 5新たな実装によるASP.NET 
ASP.NET 4.6現行ASP.NETの進化版 
ASP.NET 5は.NET Coreでも動作する 
#nds39 35
.NET Core 
.NET Frameworkのサーバーサイド部分のサブセット 
デスクトップ開発用のライブラリを含まない 
オープンソース化が決定 
.NET Core がオープンソースに http://blogs.msdn.com/b/visualstudio_jpn/archive/2014/11/13/net-core-is-open-source.aspx 
Mac、Linux向けのランタイムも提供される 
#nds39 36
.NET 2015 
#nds39 37 
http://blogs.msdn.com/b/dotnet/archive/2014/11/12/net-core-is-open-source.aspx
ASP.NET 5でどうなるか? 
ASP.NET 5のアプリケーション構成 
IIS 
(Winのみ) 
or 
kestrel, 
セルフホスト (Win,Mac,Linux) 
.NET 
Webアプリ 
すべての主要プラットフォーム上で動作し、 ランタイムの差し替えもできる 
#nds39 38 
ASP.NET 5 
HTTP(S) 
.NET 4.6(Winのみ) or 
.NET Core 5, 
Mono(Win,Mac,Linux)
ASP.NET 5でどうなるか? 
ASP.NET 5のアプリケーション構成 
IIS 
(Winのみ) 
or 
kestrel, 
セルフホスト (Win,Mac,Linux) 
.NET 
Webアプリ 
すべての主要プラットフォーム上で動作し、 ランタイムの差し替えもできる 
#nds39 39 
ASP.NET 5 
HTTP(S) 
.NET 4.6(Winのみ) or 
.NET Core 5, 
Mono(Win,Mac,Linux) 
OWINじゃない!?
The OWIN is dead!? 
ASP.NET 5ではOWINをASP.NETのコア部分に再実装 
Microsoft.AspNet.Http名前空間 
Owin.dllへの依存はなく互換性はない 
OwinIAppBuilder 
ASP.NET 5IApplicationBuilder 
#nds39 40
Long livethe OWIN! 
OWINの概念は継承されているので、 同じようにミドルウェアを作成できる 
既存のOWINミドルウェアは互換レイヤーを使えば利用可能 
ASP.NET 4.6では現行のOWIN実装しか使えない 
#nds39 41
ASP.NET 5 Preview 
DEMO 
#nds39 42 
•Basic認証ミドルウェアの使用
Conclusion 
#nds39 43
Conclusion 
OWINはWebサーバーとWebアプリ間の インターフェース定義 
PerlでいうPSGIにあたる 
ミドルウェアを組み合わせて柔軟でプラガブルな構成 
OWINはIISに囚われない 
セルフホストが可能 
Monoでも動作する 
#nds39 44
Conclusion 
リファレンス実装はKatanaプロジェクト 
Microsoft.Owin 
ASP.NET5ではKatanaプロジェクトではなく一から再実装 
Microsoft.AspNet.Http 
Windows、Mac、Linux向けの.NET Coreでも動く 
The OWIN is dead. Long live the OWIN. 
#nds39 45
Ask me any questions! 
#nds39 46

More Related Content

PPTX
Manufacturing Process of Tyre
PPTX
Design of compound die
PDF
Design and analysis of punching die
PPTX
Forging
PPTX
Lathe machine
PDF
U4 p4 sheet metal operation
PPTX
Tolerance zone shapes in GD&T
PPTX
Special Machines Unit 2: Reciprocating machines
Manufacturing Process of Tyre
Design of compound die
Design and analysis of punching die
Forging
Lathe machine
U4 p4 sheet metal operation
Tolerance zone shapes in GD&T
Special Machines Unit 2: Reciprocating machines

What's hot (20)

DOCX
DFMA report
PPTX
GD&T - PPT
PDF
A closed form solution for stress concentration around a circular hole in a l
PPTX
Limits, fits, tolerance
PDF
Hermite bicubic-surface-patch
PPTX
Eden Rolt Comparator
PPTX
Casting
PPTX
PDF
Gdt symbols reference
PDF
Hsk level 4 vocabularies by frequency
PDF
Additive Manufacturing Process Simulation and Generative Design-Production of...
PDF
Tata valuation by aswath
PPTX
Skin stringers-in-an-aircraft
PPTX
Design for assembly methods
PPT
Fasteners (2)
PPTX
14 symbols of gd&t
PPTX
Topology Optimisation for 3D Printing
PPTX
Ch 24 limit, tolerance &amp; fits
PPTX
Baja vehicle chasis design &amp; analysis
DFMA report
GD&T - PPT
A closed form solution for stress concentration around a circular hole in a l
Limits, fits, tolerance
Hermite bicubic-surface-patch
Eden Rolt Comparator
Casting
Gdt symbols reference
Hsk level 4 vocabularies by frequency
Additive Manufacturing Process Simulation and Generative Design-Production of...
Tata valuation by aswath
Skin stringers-in-an-aircraft
Design for assembly methods
Fasteners (2)
14 symbols of gd&t
Topology Optimisation for 3D Printing
Ch 24 limit, tolerance &amp; fits
Baja vehicle chasis design &amp; analysis
Ad

Viewers also liked (7)

PDF
仕事が捗る! Office & エディター操作入門 #nds40
PDF
設計(≒デザイン)の話をしよう #nds35
PPTX
Visual studio 2015 update1 ctpとcsi
PPTX
ライトニングトーク Windows10体験記 201510_山p(アップロード用)
PDF
業務アプリケーション開発を支える.NET技術 #ngtnet
PPTX
大人の基礎C#【Niigat.NET 2015-10】
PDF
アプリしか作れないけどAzureに触ってみた #ngtnet
仕事が捗る! Office & エディター操作入門 #nds40
設計(≒デザイン)の話をしよう #nds35
Visual studio 2015 update1 ctpとcsi
ライトニングトーク Windows10体験記 201510_山p(アップロード用)
業務アプリケーション開発を支える.NET技術 #ngtnet
大人の基礎C#【Niigat.NET 2015-10】
アプリしか作れないけどAzureに触ってみた #ngtnet
Ad

Similar to OWIN - .NETにおけるPSGI - (20)

PDF
OWIN って何?
PDF
One ASP.NET, OWIN & Katana
PDF
Cloud から IoT まで、なんでもおまかせ ~ .NET 5 正式リリース!
PPTX
今から始める、Windows 10&新.NETへの移行戦略
PDF
.NET の今と今後に思うこと
PDF
ASP.NET vNext / Visual Studio "14" に見る .NET の未来像
PDF
SignalRブートキャンプ
PDF
.NET の過去、現在、そして未来 ~ .NET 最新アップデート
PDF
~ Cloud First から Cloud Optimized へ ~ .NET on Cloud が描くモダナイゼーション
PDF
A 1-2 One ASP.NET - ASP.NET Web Stack
PDF
.NET Core と Container, そして Azure Web Apps on Linux による Web アプリ開発最前線
PDF
.NET最先端技術によるハイパフォーマンスウェブアプリケーション
PDF
最新 .NET テクノロジと次世代型アプリ開発 2013 : DE-011, MSC 2013
PPT
20010127
PPTX
About .Net vNext
PPTX
About .Net vNext
PDF
20140830 2014年版 C #でできること
PDF
ASP.NET "NOW" and "NEXT"
PDF
[TL04] .NET 15 周年の今こそ考えるクラウドネイティブ アプリケーションと .NET の活用
PPT
20060419
OWIN って何?
One ASP.NET, OWIN & Katana
Cloud から IoT まで、なんでもおまかせ ~ .NET 5 正式リリース!
今から始める、Windows 10&新.NETへの移行戦略
.NET の今と今後に思うこと
ASP.NET vNext / Visual Studio "14" に見る .NET の未来像
SignalRブートキャンプ
.NET の過去、現在、そして未来 ~ .NET 最新アップデート
~ Cloud First から Cloud Optimized へ ~ .NET on Cloud が描くモダナイゼーション
A 1-2 One ASP.NET - ASP.NET Web Stack
.NET Core と Container, そして Azure Web Apps on Linux による Web アプリ開発最前線
.NET最先端技術によるハイパフォーマンスウェブアプリケーション
最新 .NET テクノロジと次世代型アプリ開発 2013 : DE-011, MSC 2013
20010127
About .Net vNext
About .Net vNext
20140830 2014年版 C #でできること
ASP.NET "NOW" and "NEXT"
[TL04] .NET 15 周年の今こそ考えるクラウドネイティブ アプリケーションと .NET の活用
20060419

More from 将 高野 (13)

PDF
新入社員研修の作り方 〜完全版〜 by @masaru_b_cl #nds57
PDF
新しい世界の学び方 by @masaru_b_cl #nds55
PDF
C#でアプリを作ってみよう! #ngtnet
PDF
Let's LINQing! - C#におけるデータ処理 - by @masaru_b_cl #nds51
PDF
Lightweight C#
PDF
はじめてのReleaseブランチ運用(svn編)
PDF
git-svn
PDF
GTD on RTM
PDF
Tddのすゝめ
PDF
効率10倍UP 秀丸IDE化法
PDF
Choi LINQ
PDF
Lets Enjoy C#!
PPT
Hello ".NET" World
新入社員研修の作り方 〜完全版〜 by @masaru_b_cl #nds57
新しい世界の学び方 by @masaru_b_cl #nds55
C#でアプリを作ってみよう! #ngtnet
Let's LINQing! - C#におけるデータ処理 - by @masaru_b_cl #nds51
Lightweight C#
はじめてのReleaseブランチ運用(svn編)
git-svn
GTD on RTM
Tddのすゝめ
効率10倍UP 秀丸IDE化法
Choi LINQ
Lets Enjoy C#!
Hello ".NET" World

OWIN - .NETにおけるPSGI -