This documentation is archived and is not being maintained.

Inheriting from the WebService Class

By default, XML Web services created by using the ASP.NET Web Service project template inherit from the System.Web.Services.WebSerivce class. Inheriting this class makes it possible for the XML Web service to access the ASP.NET intrinsic objects, such as Application and Session. For more information, see Inheritance (Visual Basic .NET) or 10.2.1 Inheritance (C#)

Note   If your class does not inherit from the WebService class, the Component Designer for the XML Web service will not be available.

If the XML Web service does not inherit from this class, it can access the ASP.NET intrinsic objects from System.Web.HttpContext.Current. This can be the case when your XML Web service needs to inherit from a custom base class. The class implementing the XML Web service must be public and must have a public default constructor (a constructor without parameters). This makes it possible for ASP.NET to create an instance of the XML Web service class to process incoming XML Web service requests. For more information, see HttpContext.Current Property.

To inherit from the System.Web.Services.WebService class

  • You can inherit from the System.Web.Services.WebService class as shown in the example below:
    ' Visual Basic
    Public Class Service1
        Inherits System.Web.Services.WebService
        <System.Web.Services.WebMethod( _
           Description:="Get SessionID", _
           EnableSession:=True)> _
        Public Function GetSessionID() As String
            GetSessionID = Me.Session.SessionID
        End Function
    End Class
    // C#
    public class Service1 : System.Web.Services.WebService
           Description="Get SessionID",
        public string GetSessionID()
            return this.Session.SessionID;

See Also

Creating XML Web Services in Managed Code | WebService Class | HttpContext.Current Property