Tuesday, 8 October 2013

Lifecycle of an ASP.NET Web API

ASP.NET net API, as we all know currently, could be a framework that helps build Services over hypertext transfer protocol. net API was introduced as a light-weight service framework keeping in mind the fashionable net development paradigm wherever multiple devices associated consumer platforms access information via an API that’s created accessible over plain hypertext transfer protocol while not the configuration overhead of WS-* style of Services. It doesn't impose client-side object proxy needs and supports JSON and XML formats out-of-the-box  for information transfer over the wire.

Today, we'll investigate the Lifecycle of associate ASP.NET net API message because it travels from the server to the consumer via the HttpRequest and back via the HttpResponse. we'll additionally investigate the varied extensibility points within the pipeline. once more due to net API professional Sumit Maitra for all his valuable inputs.

The original flow chart was created by Microsoft and may be downloaded from here. The illustrations below square measure galvanized by this original diagram.

As we are able to see, net API may be hosted either on ASP.NET otherwise you might write a Console App or a Windows Service yourself to self-host it in an exceedingly instrumentality of yours. thus net API’s flexibility starts right at the core on wherever it may be hosted. This extremely opens things up for United States of America as we have a tendency to act.

a. ASP.NET Hosting: once hosted on ASP.NET, the lifecycle starts with the HttpControllerHandler that is associate implementation of IHttpAsyncHandler and is liable for passing requests into the HttpServer pipeline.

b. Self Hosting: after you square measure Self Hosting, the HttpServer pipeline starts at the HttpSelfHostServer that is associate implementation of HttpServer and directly listens to hypertext transfer protocol requests.

Once an invitation leaves your Service host, it travels as associate HttpRequestMessage object within the pipeline. ensuing stage within the pipeline square measure the Message Handlers.

Delegating Handler

Delegating handlers square measure associate extensibility purpose within the message pipeline permitting you to massage the Request before passing it on to the remainder of the pipeline. The response message on its approach back has got to go through the authorization Handler in addition, thus any response may be monitored/filtered/updated at this extensibility purpose.

Delegating Handlers if needed, will bypass the remainder of the pipeline too and challenge and hypertext transfer protocol Response themselves.

0 comments:

Post a Comment