WebService Class (System.Web.Services) (2024)

  • Reference

Definition

Namespace:
System.Web.Services
Assembly:
System.Web.Services.dll

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

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

public ref class WebService : System::ComponentModel::MarshalByValueComponent
public class WebService : System.ComponentModel.MarshalByValueComponent
type WebService = class inherit MarshalByValueComponent
Public Class WebServiceInherits MarshalByValueComponent
Inheritance

Object

MarshalByValueComponent

WebService

Derived

System.Workflow.Activities.WorkflowWebService

Examples

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(); } }
<%@ WebService Language="VB" Class="Util" %> Imports SystemImports System.Web.ServicesPublic Class Util Inherits WebService <WebMethod(Description := "Returns the time as stored on the Server", _ EnableSession := False)> _ Public Function Time() As String Return Context.Timestamp.TimeOfDay.ToString() End FunctionEnd Class

Remarks

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.

Constructors

WebService()

Initializes a new instance of the WebService class.

Properties

Application

Gets the application object for the current HTTP request.

Container

Gets the container for the component.

(Inherited from MarshalByValueComponent)
Context

Gets the ASP.NET HttpContext for the current request, which encapsulates all HTTP-specific context used by the HTTP server to process Web requests.

DesignMode

Gets a value indicating whether the component is currently in design mode.

(Inherited from MarshalByValueComponent)
Events

Gets the list of event handlers that are attached to this component.

(Inherited from MarshalByValueComponent)
Server

Gets the HttpServerUtility for the current request.

Session

Gets the HttpSessionState instance for the current request.

Site

Gets or sets the site of the component.

(Inherited from MarshalByValueComponent)
SoapVersion

Gets the version of the SOAP protocol used to make the SOAP request to the XML Web service.

User

Gets the ASP.NET server User object. Can be used to authenticate whether a user is authorized to execute the request.

Methods

Dispose()

Releases all resources used by the MarshalByValueComponent.

(Inherited from MarshalByValueComponent)
Dispose(Boolean)

Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources.

(Inherited from MarshalByValueComponent)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetService(Type)

Gets the implementer of the IServiceProvider.

(Inherited from MarshalByValueComponent)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

(Inherited from MarshalByValueComponent)

Events

Disposed

Adds an event handler to listen to the Disposed event on the component.

(Inherited from MarshalByValueComponent)

Extension Methods

GetKeyedService<T>(IServiceProvider, Object)

Gets a service of type T from the IServiceProvider.

GetKeyedServices(IServiceProvider, Type, Object)

Gets an enumeration of services of type serviceType from the IServiceProvider.

GetKeyedServices<T>(IServiceProvider, Object)

Gets an enumeration of services of type T from the IServiceProvider.

GetRequiredKeyedService(IServiceProvider, Type, Object)

Gets a service of type serviceType from the IServiceProvider.

GetRequiredKeyedService<T>(IServiceProvider, Object)

Gets a service of type T from the IServiceProvider.

CreateAsyncScope(IServiceProvider)

Creates a new AsyncServiceScope that can be used to resolve scoped services.

CreateScope(IServiceProvider)

Creates a new IServiceScope that can be used to resolve scoped services.

GetRequiredService(IServiceProvider, Type)

Get service of type serviceType from the IServiceProvider.

GetRequiredService<T>(IServiceProvider)

Get service of type T from the IServiceProvider.

GetService<T>(IServiceProvider)

Get service of type T from the IServiceProvider.

GetServices(IServiceProvider, Type)

Get an enumeration of services of type serviceType from the IServiceProvider.

GetServices<T>(IServiceProvider)

Get an enumeration of services of type T from the IServiceProvider.

GetFakeLogCollector(IServiceProvider)

Gets the object that collects log records sent to the fake logger.

GetFakeRedactionCollector(IServiceProvider)

Gets the fake redactor collector instance from the dependency injection container.

Applies to

WebService Class (System.Web.Services) (2024)

References

Top Articles
Latest Posts
Article information

Author: Mrs. Angelic Larkin

Last Updated:

Views: 5861

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Mrs. Angelic Larkin

Birthday: 1992-06-28

Address: Apt. 413 8275 Mueller Overpass, South Magnolia, IA 99527-6023

Phone: +6824704719725

Job: District Real-Estate Facilitator

Hobby: Letterboxing, Vacation, Poi, Homebrewing, Mountain biking, Slacklining, Cabaret

Introduction: My name is Mrs. Angelic Larkin, I am a cute, charming, funny, determined, inexpensive, joyous, cheerful person who loves writing and wants to share my knowledge and understanding with you.