Export (0) Print
Expand All

WebService Class

Defines the optional base class for XML Web services, which provides direct access to common ASP.NET objects, such as application and session state.

Namespace:  System.Web.Services
Assembly:  System.Web.Services (in System.Web.Services.dll)

public class WebService : MarshalByValueComponent

The WebService type exposes the following members.

  NameDescription
Public methodWebServiceInitializes a new instance of the WebService class.
Top

  NameDescription
Public propertyApplicationGets the application object for the current HTTP request.
Public propertyContainerGets the container for the component. (Inherited from MarshalByValueComponent.)
Public propertyContextGets the ASP.NET HttpContext for the current request, which encapsulates all HTTP-specific context used by the HTTP server to process Web requests.
Public propertyDesignModeGets a value indicating whether the component is currently in design mode. (Inherited from MarshalByValueComponent.)
Protected propertyEventsGets the list of event handlers that are attached to this component. (Inherited from MarshalByValueComponent.)
Public propertyServerGets the HttpServerUtility for the current request.
Public propertySessionGets the HttpSessionState instance for the current request.
Public propertySiteGets or sets the site of the component. (Inherited from MarshalByValueComponent.)
Public propertySoapVersionGets the version of the SOAP protocol used to make the SOAP request to the XML Web service.
Public propertyUserGets the ASP.NET server User object. Can be used to authenticate whether a user is authorized to execute the request.
Top

  NameDescription
Public methodDispose()Releases all resources used by the MarshalByValueComponent. (Inherited from MarshalByValueComponent.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources. (Inherited from MarshalByValueComponent.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from MarshalByValueComponent.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetServiceGets the implementer of the IServiceProvider. (Inherited from MarshalByValueComponent.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from MarshalByValueComponent.)
Top

  NameDescription
Public eventDisposedAdds an event handler to listen to the Disposed event on the component. (Inherited from MarshalByValueComponent.)
Top

If you don't need access to the common ASP.NET objects, you can still create an XML Web service without deriving from WebService. Additional ASP.NET objects can be accessed through Context.

XML Web service methods that have the OneWay property of either SoapRpcMethodAttribute or SoapDocumentMethodAttribute set to true, do not have access to their HttpContext. As such, accessing any of the properties of the WebService class, from within that XML Web service method, return null.

If you are using the .NET Framework version 1.0 XML Web service methods that have either the SoapRpcMethodAttribute or SoapDocumentMethodAttribute attribute applied to them with the OneWay property of set to true, do not have access to their HttpContext using the static Current property. To access the HttpContext, derive the class implementing the XML Web service method from WebService and access the Context property.

TopicLocation
Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio

The example below creates an XML Web service, deriving from WebService, in order to use the Context property to obtain the time of the request on the server.

<%@ WebService Language="C#" Class="Util" %>

 using System;
 using System.Web.Services;

 public class Util: WebService {
   [ WebMethod(Description="Returns the time as stored on the Server",
   EnableSession=false)]
   public string Time() {
      return Context.Timestamp.TimeOfDay.ToString();
   }
 }
 

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft