ASMX equivalent of Page_Init?

前端 未结 3 2252
醉酒成梦
醉酒成梦 2021-02-20 16:24

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

3条回答
  •  失恋的感觉
    2021-02-20 16:44

    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.

    e.g.

        [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;
            }
        }
    

提交回复
热议问题