About the ASP. NET WEB API message processing pipeline (ii)

Source: Internet
Author: User

In this article on the ASP. NET Web API message processing pipeline, by flipping through source code and instance validation, we know the types of ASP. NET Web API message processing pipeline and how the ASP. NET Web API creates the message processing pipeline. On the basis of this article, I would like to add a few words on how the request is entered into the message processing pipeline of the ASP. Webhost boarding and Selfhost boarding methods.

Webhost Boarding Method:

In the article Anatomy of the ASP. NET Webapi routing system, we know that the ASP. Web API webhost The Httpcontrollerhandler type as the HttpHandler of the request. And because the ASP. NET Web API is hosted in webhost, the request is processed using the ASP. The Processrequestasync method in the Httpcontrollerhandler type representing HttpHandler is executed during the ASP. NET pipeline event flow, and this method is the ASP. NET Web API message processing pipeline portal, look at the source code we can verify:

As you can see, the entry into the ASP. NET WEB API message processing pipeline is the Processrequestasync method in Httpcontrollerhandler, in the webhost homestay mode. By default, Httpserver and Httproutingdispatcher are used as "Taps" and "Dragon Tails" as message processing pipelines. After the processing of each node of the ASP. NET WEB API message processing pipeline, the request is reversed back to Httpcontrollerhandler and the response message is returned to the client via ASP.

After analyzing how to enter the ASP. NET WEB API message processing pipeline under Webhost Homestay mode, continue to see how the Selfhost homestay works.

Selfhost Boarding Method:

Before we go on, let's look at an example of the ASP. NET Web API hosting in Selfhost mode. Create a new console project and add a class named Democontroller:

     Public class Democontroller:apicontroller    {        publicstring  Get ()        {            return"ASP. WebAPI selfhost";        }    }
    classProgram {Static voidMain (string[] args) {httpselfhostconfiguration configuration=NewHttpselfhostconfiguration ("http://localhost:9999/"); using(Httpselfhostserver server =Newhttpselfhostserver (configuration)) {Server. Configuration.Routes.MapHttpRoute (Name:"Defaultapi", Routetemplate:"Api/{controller}"); Server.                OpenAsync ();            Console.read (); }        }    }

Browser view:

Now let's start with this demo to dissect how the ASP. NET Web API is in the Selfhost homestay mode, how to enter the message processing pipeline. First look at the httpselfhostconfiguration type, as below, httpselfhostconfiguration inherit to Httpconfiguration. In the example above, we pass it to an address that will be used to listen to the request:

Next look at the Httpselfhostserver source code, as follows. Httpselfhostserver inherits to Httpserver, it appears that Httpselfhostserver will be the "faucet" of the ASP. NET WEB API message processing pipeline:

The "dragon Tail" of the ASP. NET WEB API message processing pipeline, Httproutingdispatcher becomes the "dragon tail" of the message processing pipeline under Selfhost Homestay mode:

According to the example code above, when the listener port is finished with the pin, the route is registered, the Openasync method called Httpselfhostserver begins to receive the request. So, what does it do within the Openasync method? Let's take a look at the details below:

By the above analysis process can be known, in the Selfhost boarding mode, the ASP. NET Web API through the httpbinding for the request to listen and respond to the response. The httpselfhostserver that inherits to Httpserver directly serves as the "faucet" of the message processing pipeline. With the help of httpbinding, the listener of the request is completed, the request enters the message processing pipeline for processing, and responds to the reply of the message.

At this point, the ASP. NET Web API in Webhost and selfhost two boarding methods, the request how to enter the message processing pipeline profiling complete. The ability is limited, if wrong, welcome to make a correction.

About the ASP. NET WEB API message processing pipeline (ii)

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.