10

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...)

Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • I would point out that this is fairly implementation-dependant information, especially considering that ASMX has pretty much been replaced by WCF, which has a totally different lifecycle. – John Saunders Oct 20 '10 at 21:02

2 Answers2

9

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.

RPM1984
  • 72,246
  • 58
  • 225
  • 350
1

asmx objects are not derived from Page, rather from System.Web.Services.WebService, so they will not have the events you are looking for.

Otávio Décio
  • 73,752
  • 17
  • 161
  • 228