asp.net - What is the complete lifecycle of an OData controller http request in WebApi 2 -
i wonder full lifecycle of odata http request on odatacontroller hosted in iis.
for instance:
- what iis pipelining steps ?
- how request handled when entering asp.net controllers area ?
- when routing applied ?
- when attributes such
httppost,applyfilterapplied ?
maybe thread can you: the asp.net web api 2 http message lifecycle in 43 easy steps
- iis (or owin self-hosting) receives request.
the request passed instance of httpserver.

httpserver responsible dispatching httprequestmessage objects.
if 1 or more global instances of delegatinghandler exist on pipeline, request passed it. request arrives @ instances of delegatinghandler in order said instances added pipeline.
delegatinghandler instances can skip remainder of pipeline , create own response. in custom validation fluentvalidation post.
- if httprequestmessage passes delegatinghandler instances (or no such handler exists), request proceeds httproutingdispatcher instance.
httproutingdispatcher chooses routing handler call based on matching route. if no such route exists (e.g. route.handler null, seen in diagram) request proceeds directly step 10. 
- if route handler exists given route, httprequestmessage sent handler.
- it possible have instances of delegatinghandler attached individual routes. if such handlers exist, request goes them (in order added pipeline).
- an instance of httpmessagehandler handles request. if provide custom httpmessagehandler, said handler can optionally return request "main" path or custom end point.

- the request received instance of httpcontrollerdispatcher, route request appropriate route determined request's url.

- the httpcontrollerdispatcher selects appropriate controller route request to.
- an instance of ihttpcontrollerselector selects appropriate httpcontrollerdescriptor given httpmessage.
- the ihttpcontrollerselector calls instance of ihttpcontrollertyperesolver, call...
- an instance of iassembliesresolver, selects appropriate controller , returns httpcontrollerdispatcher step 11. note: if implement dependency injection, iassembliesresolver replaced whatever container register.
- once httpcontrollerdispatcher has reference appropriate controller, calls create() method on ihttpcontrolleractivator...
- which creates actual controller , returns dispatcher. dispatcher sends request select controller action routine, shown below.

- we have instance of apicontroller represents actual controller class request routed to. said instance calls selectaction() method on ihttpactionselector...
- which returns instance of httpactiondescriptor representing action needs called.

- once pipeline has determined action route request to, executes authentication filters inserted pipeline (either globally or local invoked action). these filters allow authenticate requests either individual actions, entire controllers, or globally throughout application. filters exist executed in order added pipeline (global filters first, controller-level filters, action-level filters).
- the request proceeds [authorization filters] layer, authorization filters exist applied request. authorization filters can optionally create own response , send back, rather allowing request proceed through pipeline. these filters applied in same manner authentication filters (globally, controller-level, action-level). note authorization filters can used on request, not response, assumed if response exists, user had authorization generate it.
- the request enters model binding process, shown in next part of main poster. each parameter needed action can bound value 1 of 3 separate paths. path binding system uses depends on value needed exists within request.

- if data needed action parameter value exists in entity body, web api reads body of request; instance of formatterparameterbinding invoke appropriate formatter classes...
- which bind values media type (using mediatypeformatter)...
- which results in new complex type.
- if data needed parameter value exists in url or query string, said url passed instance of imodelbinder, uses ivalueprovider map values model (see phil haack's post topic more info)....
- which results in simple type.
- if custom httpparameterbinding exists, system uses custom binding build value...
- which results in kind (simple or complex) of object being mappable (see mike stall's wonderful series on topic).

- now request bound model, passed through action filters may exist in pipeline (either globally or action being invoked).
- once action filters passed, action invoked, , system waits response it.

- if action produces exception , exception filter exists, exception filter receives , processes exception.
- if no exception occurred, action produces instance of httpresponsemessage running result conversion subroutine, shown in next screenshot.

- if return type httpresponsemessage, don't need conversion, pass return on through.
- if return type void, .net return httpresponsemessage status 204 no content.
- if return type ihttpactionresult, call method executeasync create httpresponsemessage. in web api method in use return ok(); or return badrequest(); or similar, return statement follows process, rather of other processes, since return type of actions ihttpactionresult.
- for other types, .net create httpresponsemessage , place serialized value of return in body of message.
- once httpresponsemessage has been created, return main pipeline.

- pass newly-created httpresponsemessage through authenticationfilters may exist.

- the httpresponsemessage flows through httpcontrollerdispatcher, @ point won't it.
- the response flows through httproutingdispatcher, again won't it.
- the response proceeds through delegatinghandlers set handle it. @ point, delegatinghandler objects can change response being sent (e.g. intercept responses , change appropriate http status).

- the final httpresponsemessage given httpserver instance.
- which returns http response invoking client


Comments
Post a Comment