本文介绍了ASMX相当于Page_Init吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code,我想在一个ASMX函数调用的生命周期很早就执行。对于我们的ASPX页面,这code是在一个基类中的Page_Init()函数,从中我们所有的ASPX页面继承。

I have some code I would like to execute very early in the lifecycle of a call to an ASMX function. For our ASPX pages, this code is in the Page_Init() function on a base class, from which all our ASPX pages inherit.

是否有一个ASMX相当于ASPX的Page_Init()函数?

Is there an ASMX equivalent to the ASPX's Page_Init() function?

更重要的是,有没有像ASPX之一的ASMX生命周期图?

Better yet, is there an ASMX lifecycle diagram like the ASPX one? http://msdn.microsoft.com/en-us/library/ms178472.aspx

如果有一个ASMX相当于Page_Init(),我想我可以在一个共同的基类实现code,从中我所有的ASMX类可以继承,是否正确?

If there is an ASMX equivalent to Page_Init(), I assume I can implement code in a common base class, from which all my ASMX classes can inherit, correct?

编辑:
大的反应 - 感谢您的帮助

Great responses - thanks for your help!

推荐答案

有没有真正在ASMX Web服务这样的事情,System.Web.Services.WebService没有任何事件。最好的办法是创建一个默认的构造函数,并把它放在那里。

There isn't really such a thing in an asmx web service, System.Web.Services.WebService has no events. Your best bet is to create a default constructor and put it in there.

例如

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class WebService1 : System.Web.Services.WebService
    {
        private string strRetVal;

        public WebService1()
        {
            strRetVal = "Hello World";
        }

        [WebMethod]
        public string HelloWorld()
        {
            return strRetVal;
        }
    }

这篇关于ASMX相当于Page_Init吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:09