ASP. NET Web API runtime framework

Source: Internet
Author: User

Introduction

This article mainly describes the framework for running ASP. NET Web APIs, that is, the process from receiving an HttpRequest to the corresponding process.

Runtime framework

The API framework consists of three layers: hosting (host), message handler (message processing pipeline), and controller handler (controller processor)

 

Hosting host

The bottom layer is responsible for the web api host, for example, this interface is in the Web API and HTTP Runtime. Simply put, this layer is responsible for creating HttpRequestMessage instances and pushing them to the previous layer of Message Processing pipelines. At the same time, this layer is also responsible for returning HttpResponseMessage to the MPs queue.

Generally, two existing hosting options are available: SelfHost and WebHost.
SelfHost is based on WCF. It replaces the Message with HttpRequestMessage and pushes it to the upper-layer Message processing pipeline.
WebHosting converts HttpRequest to HttpRequestMessage Based on HttpControllerHandler.

The WebAPI host is not limited to the two, but also contributed by some communities, such as Louis Dejardin's OWIN and the author's host, based on Azure Service.

Message Handler Pipeline Message processing Pipeline

The middle layer is composed of a message processing pipeline, similar to an existing WCF Web API. This pipeline exposes an HttpServer class, which also extends the HttpMessageHandler (combination mode ).

This pipeline provides some scalability points, such as logs and user authentication.

There is a special handler at the upper layer of the pipeline: HttpControllerDispatcher. This handler is responsible for obtaining and calling a controller for this request.

HttpControllerDispathcer is used only when the controller-based programming model controller base-class programming mode (ApiController inherits this class) is used. Normally, we are all encoded based on this mode.

Controller Handling Controller Processor

Finally, the upper layer is equivalent to the controller's processing process, as shown in the following figure:

Action selection

Filter execution

Model binding

Action call

Output content through formatters

The whole process is executed within ApiController and called by HttpControllerDispatcher.

Last

Links are added in many places to provide detailed information. Please leave a message at will.

Original article:

ASP. NET Web API Processing Architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.