WebService WebService WebService WebService Class

定义

为 XML Web services 定义可选的基类,该基类提供对公共 ASP.NET 对象(如应用程序和会话状态)的直接访问。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 WebService
Inherits MarshalByValueComponent
继承
派生

示例

下面的示例创建了一个派生自WebService的 XML Web service, 以便Context使用属性获取服务器上的请求时间。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 System
Imports System.Web.Services

Public 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 Function
End Class

注解

如果不需要访问常见的 ASP.NET 对象, 则仍可以创建 XML Web service, 而不是从WebService派生。If you don't need access to the common ASP.NET objects, you can still create an XML Web service without deriving from WebService. 可以通过Context访问其他 ASP.NET 对象。Additional ASP.NET objects can be accessed through Context.

如果 XML Web service 方法的OneWay属性SoapRpcMethodAttribute为或SoapDocumentMethodAttribute设置为true, 则无法访问其HttpContextXML Web service methods that have the OneWay property of either SoapRpcMethodAttribute or SoapDocumentMethodAttribute set to true, do not have access to their HttpContext. 因此, 从该 XML Web service 方法中访问WebService类的任何属性, 都将返回。 nullAs such, accessing any of the properties of the WebService class, from within that XML Web service method, return null.

如果你使用的是 .NET Framework 版本 1.0 XML Web service SoapRpcMethodAttribute方法, 这些方法OneWay应用了SoapDocumentMethodAttribute或特性, 并且的属性设置HttpContexttrue, 则无权使用静态Current属性。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. 若要访问HttpContext, 请派生类实现 XML Web service WebService方法, 并访问Context属性。To access the HttpContext, derive the class implementing the XML Web service method from WebService and access the Context property.

构造函数

WebService() WebService() WebService() WebService()

初始化 WebService 类的新实例。Initializes a new instance of the WebService class.

属性

Application Application Application Application

获取当前 HTTP 请求的应用程序对象。Gets the application object for the current HTTP request.

Container Container Container Container

获取组件的容器。Gets the container for the component.

(Inherited from MarshalByValueComponent)
Context Context Context Context

获取当前请求的 ASP.NET HttpContext,它封装了由 HTTP 服务器用来处理 Web 请求的所有 HTTP 特定的上下文。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 DesignMode DesignMode DesignMode

获取指示组件当前是否处于设计模式的值。Gets a value indicating whether the component is currently in design mode.

(Inherited from MarshalByValueComponent)
Events Events Events Events

获取附加到该组件的事件处理程序的列表。Gets the list of event handlers that are attached to this component.

(Inherited from MarshalByValueComponent)
Server Server Server Server

获取当前请求的 HttpServerUtilityGets the HttpServerUtility for the current request.

Session Session Session Session

获取当前请求的 HttpSessionState 实例。Gets the HttpSessionState instance for the current request.

Site Site Site Site

获取或设置组件的位置。Gets or sets the site of the component.

(Inherited from MarshalByValueComponent)
SoapVersion SoapVersion SoapVersion SoapVersion

获取用于向 XML Web services 发送 SOAP 请求的 SOAP 协议的版本。Gets the version of the SOAP protocol used to make the SOAP request to the XML Web service.

User User User User

获取 ASP.NET 服务器 User 对象。Gets the ASP.NET server User object. 可用于验证用户是否有权执行请求。Can be used to authenticate whether a user is authorized to execute the request.

方法

Dispose() Dispose() Dispose() Dispose()

释放由 MarshalByValueComponent 使用的所有资源。Releases all resources used by the MarshalByValueComponent.

(Inherited from MarshalByValueComponent)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 MarshalByValueComponent 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources.

(Inherited from MarshalByValueComponent)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

获取 IServiceProvider 的实施者。Gets the implementer of the IServiceProvider.

(Inherited from MarshalByValueComponent)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回包含 Component 的名称的 String(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(Inherited from MarshalByValueComponent)

事件

Disposed Disposed Disposed Disposed

添加事件处理程序以侦听组件上的 Disposed 事件。Adds an event handler to listen to the Disposed event on the component.

(Inherited from MarshalByValueComponent)

适用于