什么是ASP.NET web服务请求生命周期? [英] What's the ASP.NET Webservice request lifecycle?
问题描述
在一个普通的 ASPX
页,我有这样的 Page_Init
,激发Page_Unload <事件/ code>等,其中发生在一个明确的订单。
On a regular aspx
page, I have events such as Page_Init
, Page_Unload
, etc., which occur in a well-defined order.
我有一个 ASMX
页面设置 [WebMethod的()]
秒。做类似事件的存在吗?特别是一些事件,让我来初始化一些数据(如的Page_Load
),并做一些清理工作(如激发Page_Unload
)将是非常有用的。
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.
(据我所知道的,的构造函数的 ASMX
code-隐藏类好像是叫每个WebMethod的要求,即,一个新的实例对于每个WebMethod的请求被创建的,但这仅仅是一个观察,这也不是我发现记录的地方......)
(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...)
推荐答案
是 - Otavio是正确的,没有页面事件ASMX Web服务,因为他们没有从页面派生
Yes - Otavio is correct, there is no Page events for ASMX Web Services, as they do not derive from Page.
不过,请求遵循常规 ASP.NET处理管道。
有在有关的IHttpHandler被执行的处理的一个点。这可以是一个页面,一个通用的HTTP处理程序,或web服务。
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.
这就是Web服务请求的执行情况。
This is where the web service request execution happens.
所以,这真的取决于你想在这里做什么。该构造函数应该提供一个良好的钩到pre-请求执行。如果你正在寻找的东西甚至更早,那么你可能需要挂接到一个Global.asax中的事件。
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.
这篇关于什么是ASP.NET web服务请求生命周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!