WebService 类

定义

为 XML Web services 定义可选的基类,该基类提供对公共 ASP.NET 对象(如应用程序和会话状态)的直接访问。

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 服务,以便使用 Context 属性获取服务器上请求的时间。

<%@ 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 服务,而无需从 WebService派生。 可以通过 访问 Context其他 ASP.NET 对象。

OneWaySoapDocumentMethodAttribute 的 属性设置为 trueSoapRpcMethodAttribute XML Web 服务方法无权访问其 HttpContext。 因此,从该 XML Web 服务方法中访问 类的任何属性 WebService 将返回 null

如果使用的是 .NET Framework 版本 1.0 XML Web 服务方法,这些方法应用了 SoapRpcMethodAttribute 或 属性,并将 OneWay 属性设置为 true,则无法使用 静态Current属性访问它们HttpContextSoapDocumentMethodAttribute。 若要访问 , HttpContext请从 WebService 派生实现 XML Web 服务方法的类,并访问 Context 属性。

构造函数

WebService()

初始化 WebService 类的新实例。

属性

Application

获取当前 HTTP 请求的应用程序对象。

Container

获取组件的容器。

(继承自 MarshalByValueComponent)
Context

获取当前请求的 ASP.NET HttpContext,它封装了由 HTTP 服务器用来处理 Web 请求的所有 HTTP 特定的上下文。

DesignMode

获取指示组件当前是否处于设计模式的值。

(继承自 MarshalByValueComponent)
Events

获取附加到该组件的事件处理程序的列表。

(继承自 MarshalByValueComponent)
Server

获取当前请求的 HttpServerUtility

Session

获取当前请求的 HttpSessionState 实例。

Site

获取或设置组件的站点。

(继承自 MarshalByValueComponent)
SoapVersion

获取用于向 XML Web services 发送 SOAP 请求的 SOAP 协议的版本。

User

获取 ASP.NET 服务器 User 对象。 可用于验证用户是否有权执行请求。

方法

Dispose()

释放由 MarshalByValueComponent 使用的所有资源。

(继承自 MarshalByValueComponent)
Dispose(Boolean)

释放由 MarshalByValueComponent 占用的非托管资源,还可以另外再释放托管资源。

(继承自 MarshalByValueComponent)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetService(Type)

获取 IServiceProvider 的实施者。

(继承自 MarshalByValueComponent)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回包含 Component 的名称的 String(如果有)。 不应重写此方法。

(继承自 MarshalByValueComponent)

事件

Disposed

添加用于侦听组件的 Disposed 事件的事件处理程序。

(继承自 MarshalByValueComponent)

适用于