Você está na página 1de 7

3/18/2014 ASP.

NET Web API Processing Architecture | Pedro Flix' s shared memory


http://pfelix.wordpress.com/2012/03/05/asp-net-web-api-processing-architecture/ 1/7
Skip to content
Skip to search - Accesskey = s
Pedro Flixs shared memory
ASP.NET Web API Processing Architecture
Posted in Software by pedrofelix on March 5, 2012
Introduction
This post presents a first overview of the ASP.NET Web API processing architecture: what happens since a
HTTP request is received until a response is produced.
Processing Architecture
The ASP.NET Web API processing architecture, represented in the following diagram, is composed by three
layers: hosting, message handler pipeline and controller handling.
3/18/2014 ASP.NET Web API Processing Architecture | Pedro Flix' s shared memory
http://pfelix.wordpress.com/2012/03/05/asp-net-web-api-processing-architecture/ 2/7
Hosting
The lower layer is responsible for the Web API hosting, i.e., the interface between Web API and an underlying
HTTP handling runtime. Succinctly, this layer is responsible for creating HttpRequestMessage instances, and
then pushing them into the upper message handler pipeline. The hosting layer is also responsible for processing
the HttpResponseMessage returned back from this handler pipeline.
Currently, there are two out-of-the-box hosting options: self-hosting and web hosting, i.e., hosting on top of
the ASP.NET classical pipeline.
Self-hosting is based on a pump that retrieves WCF Message instances from a WCF channel stack, converts
them into HttpRequestMessage instances and then push those into the upper message handler pipeline.
Follow
Follow Pedro Flix's
shared memory
Get every new post delivered
to your Inbox.
Enter your email address
Sign me up
Powered by WordPress.com
3/18/2014 ASP.NET Web API Processing Architecture | Pedro Flix' s shared memory
http://pfelix.wordpress.com/2012/03/05/asp-net-web-api-processing-architecture/ 3/7
Web-hosting is based on a specific IHttpAsyncHandler, named HttpControllerHandler, that converts
HttpRequest instances into HttpRequestMessage.
The Web API hosting is not limited to these two options. There are already some additional hosts, contributed
by the community:
Louis DeJardin created a host on top of OWIN.
Ive created a host based on the Azure Service Bus relaying.
Message Handler Pipeline
The middle layer is composed by a message handler pipeline, similar to the one that existed on WCF Web API.
This pipeline is exposed by the HttpServer class, which also extends HttpMessageHandler (composite pattern).
This pipeline provides the extensibility point for middleware addressing cross-cutting concerns such as: logging,
HTTP authentication, HTTP method translation,
Usually, at the top of this pipeline, there is a special handler: the HttpControllerDispatcher. This handler is
responsible for obtaining and calling a controller to handle the request.
The presence of this HttpControllerDispatcher is only required when using the controller-based programming
model (ApiController derived classes). It is also possible to mount a completely different model, just by
replacing the pipelines top message handler.
Controller Handling
Finally, the upper layer corresponds to the controller specific processing, namely:
Action selection;
Filter execution;
Model binding;
Action invocation;
Response content creation via formatters.
This processing is done inside the ApiController instance, called by the HttpControllerDispatcher.
Final Remarks
Future posts will address each one of this layers in more details. Until then, feel free to use the comments.
Share this:
Twitter 31 Reddit Google Tumblr

Like
2 bloggers like this.

3/18/2014 ASP.NET Web API Processing Architecture | Pedro Flix' s shared memory
http://pfelix.wordpress.com/2012/03/05/asp-net-web-api-processing-architecture/ 4/7
Tagged with: asp.net web api
6 comments
Enabling HTTPS with self-hosted ASP.NET Web API
ASP.NET Web API: in-memory hosting
6 Responses
Subscribe to comments with RSS.
1. Livingston said, on March 7, 2012 at 5:10 pm
Where can I plug into the validation? I would like to replace DataAnnotationsModelValidator and use
FluentValidation on my models
Reply
pedrofelix said, on March 7, 2012 at 10:11 pm
Take a look at http://weblogs.asp.net/cibrax/archive/2012/02/23/validating-your-models-in-asp-
net-web-api.aspx for
Reply
Livingston said, on March 10, 2012 at 7:00 am
In that example, the model is validated using attributes and through the ValidationActionFilter
you get access to the model state.
what I want to do is plug into the pipeline, apply my own validation rules without attributes,
which would then populate the modelsate errors accessible in ValidationActionFilter
2. KnowYourStack - What is ASP.NET WebAPI said, on March 16, 2012 at 2:43 pm
[...] More [...]
Reply
neaflo said, on May 26, 2012 at 10:46 am
Related
ASP.NET Web API: in-memory
hosting
ASP.NET Web API: web hosting ASP.NET Web API: self-hosting
In "Software"
In "Software" In "Software"
3/18/2014 ASP.NET Web API Processing Architecture | Pedro Flix' s shared memory
http://pfelix.wordpress.com/2012/03/05/asp-net-web-api-processing-architecture/ 5/7
Hi Pedro,
Are you aware of any performance comparisons between Web API and WCFs
WebHttpEndpoint?
Reply
3. Session: Deep-Dive to ASP.NET Web API - Gunnar Peipman's ASP.NET blog said, on
September 4, 2012 at 3:52 pm
[...] ASP.NET Web API Processing Architecture (Pedro Flix) [...]
Reply
Leave a Reply
Feed subscription
Pages
About
Recent Posts
Using HttpClient with SSL/TLS-based client side authentication
Slides for the OAuth 2.0: Theory and Practice session
JSON Web Tokens and the new JWTSecurityTokenHandler class
ASP.NET Web API: Creating an Host using Azure Service Bus
ASP.NET Web API: self-hosting
Top Posts & Pages
JSON Web Tokens and the new JWTSecurityTokenHandler class
Enabling HTTPS with self-hosted ASP.NET Web API
WCF Web API - Self-hosting, HTTPS and HTTP Basic Authentication
ASP.NET Web API Processing Architecture
Self-hosting ASP.NET Web API
ASP.NET Web API: web hosting
Using HttpClient with SSL/TLS-based client side authentication
The new .NET HttpClient class
The new System.Net.Http classes: message content
Enter your comment here...
3/18/2014 ASP.NET Web API Processing Architecture | Pedro Flix' s shared memory
http://pfelix.wordpress.com/2012/03/05/asp-net-web-api-processing-architecture/ 6/7
ASP.NET Web API: in-memory hosting
Archives
December 2012
November 2012
March 2012
February 2012
January 2012
October 2011
September 2011
August 2011
May 2011
April 2011
October 2010
July 2010
June 2010
April 2010
February 2010
December 2009
November 2009
October 2009
June 2009
May 2009
April 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
.NET Services access control Access Control Service algorit hms AppFabric AppFabric WCF Azure cloud asp.net
web api azure books c# c c# java jaxb xml C# LINQ claims concurrency CSD DevDays09 Eclipse federat ion
Geneva HTTP HTTP .NET HTTPS identity Ident it y Securit y WS-* IIS java JWT life MVP protocols remix09 SAML
Security Service Bus slides t eaching TPL WCF WCF Web API web services WIF WS-* WSDL
Zermatt
3/18/2014 ASP.NET Web API Processing Architecture | Pedro Flix' s shared memory
http://pfelix.wordpress.com/2012/03/05/asp-net-web-api-processing-architecture/ 7/7
Blog at WordPress.com. The Journalist 1.3 Theme.

Você também pode gostar