Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the ASP.NET Webservice request lifecycle?

On a regular aspx page, I have events such as Page_Init, Page_Unload, etc., which occur in a well-defined order.

I have an asmx page providing [WebMethod()]s. Do similar events exist? In particular, some events that allow me to initialize some data (like Page_Load) and do some clean-up (like Page_Unload) would be extremely useful.

(As far as I can tell, the constructor of the asmx code-behind class seems to be called on every WebMethod request, i.e., a new instance is created for every WebMethod request, but this is just an observation and not something I've found documented somewhere...)

like image 311
Heinzi Avatar asked Oct 19 '10 11:10

Heinzi


People also ask

What is the Web API request life cycle?

After leaving the service host the request travels in the pipeline as a HttpRequestMessage. There is the Handler used in the Lifecycle. Delegating Handler. This handler is provided to you as a Message of the request before passing onto the rest of the pipeline.

What are the stages in ASP.NET application request?

When an ASP.NET page executes, it undergoes a life cycle that includes various stages. The important stages in the page life cycle are Initialization, Load, Control Events, Rendering and Unload.

What is the life cycle of ASP NET core?

The ASP.NET Core MVC Request Life Cycle is a sequence of events, stages or components that interact with each other to process an HTTP request and generate a response that goes back to the client. In this article, we will discuss each and every stage of ASP.NET Core MVC Request Life Cycle in detail.

How the request and response works in ASP.NET web application?

When you request for a . aspx page, it reaches the page handler. ProcessRequest method of the IHttpHandler interface which is implemented in the handler then be invoked by the HttpRuntime. After the request reaches the HttpHandler, the IIS Request Processing cycle ends and ASP.NET page life cycle starts.


1 Answers

Yes - Otavio is correct, there is no Page events for ASMX Web Services, as they do not derive from Page.

However, The request follows the regular ASP.NET processing pipeline.

There is a point in the process where the relevant IHttpHandler is executed. This can be a page, a generic HTTP handler, or a web service.

This is where the web service request execution happens.

So, it really depends on what you're trying to do here. The ctor should provide a good hook-in to pre-request execution. If you're looking for something even earlier, then you will likely need to hook into a Global.asax event.

like image 71
RPM1984 Avatar answered Sep 27 '22 18:09

RPM1984