Udostępnij za pośrednictwem


How to: Inherit from the WebService Class

 Windows Communication Foundation Services and ADO.NET Data Services

By default, XML Web services created by using the ASP.NET Web Service project template inherit from the System.Web.Services.WebService 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 in Visual Basic or Inheritance (C# Programming Guide).

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 the HttpContext.Current property. 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.

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:

    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
    
    public class Service1 : System.Web.Services.WebService 
    {
        [System.Web.Services.WebMethod(
           Description="Get SessionID",
           EnableSession=true)]
        public string GetSessionID()
        {
            return this.Session.SessionID;
        }
    }
    

See Also

Reference

WebService

Current

Other Resources

Creating Web Services in Managed Code