This articleArticleThis section mainly introduces the processing architecture of ASP. NET Web APIs: the process when an HTTP request arrives until a request is generated. The processing architecture of ASP. NET Web APIs is as follows, which consists of three layers: hosting, message handler pipeline, and controller handling ).
Host)
The underlying layer is responsible for the hosting of Web APIs, interfaces between Web APIs, and HTTP Processing engines. In a word, this layer is responsible for creating an httprequestmessage instance. Then they are pushed to the upper-layer message processing pipeline. The host layer is also responsible for the httpresponsemessage returned by the message processing pipeline. Currently, there are two built-in host options in ASP. NET Web APIs: Self-hosting and web hosting. Web Hosting is also the host in the processing pipeline of Asp.net in IIS,Self-hostingIt is a WCF message instance based on the WCF channel stack, which is then converted to the httprequestmessage instance and pushed to the upper-layer message processing pipeline.Web-hostingIt is based on ihttpasynchandler and named httpcontrollerhandler. It converts httprequest to httprequestmessage. Of course, web API hosting is scalable and not limited to these two options. You can customize it as needed,CommunitySomeone has implemented a third-party host Louis Dejardin in owin created a host.
Message handler Pipeline)
The middle layer is message handler pipeline, which is the content of the WCF web API. It is exposed through the httpserver class, and it also extends httpmessagehandler. This pipeline provides various extensions of the intermediate layer (addressing cross-cutting concerns) such as logs, HTTP verification ,......
Usually at the top of this pipeline is a special processor: httpcontrollerdispatcher. This processor is responsible for obtaining and calling a controller to process requests. Httpcontrollerdispatcher is used only when the controller-based programming model (the derived class of apicontroller) is used, or a completely different model can be used, you only need to replace the top message processor.
Controller handling)
Finally, the upper-layer controller processes the related processes, namely:
- Action selection;
- Filter execution;
- Model binding;
- Action invocation;
- Response content creation via formatters.
These processes are all completed in the apicontroller instance and called by httpcontrollerdispatcher.
The process above is still very clear. This article only briefly introduces the entire process, and the subsequent articles detail each part.