Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASMX equivalent of Page_Init?

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.

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

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

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?

EDIT: Great responses - thanks for your help!

like image 415
mikemanne Avatar asked Jun 29 '10 20:06

mikemanne


People also ask

Is Asmx outdated?

If you can work with WCF then yes the ASMX services are obsolete because the WCF can fully replace them with more performance and flexibility (multiple binding), functionality.

What is Asmx format?

What is an ASMX file? A file with . asmx extensions is an ASP.NET Web Service file that provides communication between two objects over the internet using the Simple Object Access Protocol (SOAP). It is deployed as a service on the Windows-based Web Server to process incoming request and return the response.

How do I call Asmx Web service?

Adding Reference of the Web Service in Visual Studio 1. Right click the project in Solution Explorer and choose Add Service Reference option from the context menu. 2. Now in the Add Service Reference Dialog you need to click on the Advanced button.


1 Answers

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;
        }
    }
like image 83
Ben Robinson Avatar answered Oct 06 '22 09:10

Ben Robinson