WebServiceAttribute 类

定义

用于向 XML Web services 添加附加信息,如描述其功能的字符串。

public ref class WebServiceAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class WebServiceAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface)]
public sealed class WebServiceAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type WebServiceAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface)>]
type WebServiceAttribute = class
    inherit Attribute
Public NotInheritable Class WebServiceAttribute
Inherits Attribute
继承
WebServiceAttribute
属性

示例

以下示例将 Description 的 属性设置为 "Common Server Variables"WebServiceAttribute并将 XML 命名空间设置为 http://www.microsoft.com/

<%@ WebService Language="C#" Class= "ServerVariables"%>
 
 using System;
 using System.Web.Services;
 
 [ WebService(Description="Common Server Variables",Namespace="http://www.contoso.com/")]
 public class ServerVariables: WebService {
 
 
    [ WebMethod(Description="Obtains the Server Computer Name",EnableSession=false)]
    public string GetMachineName() {
       return Server.MachineName;
    }   
 }
<%@ WebService Language="VB" Class= "ServerVariables"%>
 
Imports System
Imports System.Web.Services

<WebService(Description := "Common Server Variables", _
 Namespace := "http://www.contoso.com/")> _
Public Class ServerVariables
    Inherits WebService 
    
    <WebMethod(Description := "Obtains the Computer Machine Name", _
        EnableSession := False)> _
    Public Function GetMachineName() As String
        
        Return Server.MachineName
    End Function
End Class

注解

WebServiceAttribute发布和执行 XML Web 服务不需要 。 可以使用 WebServiceAttribute 为 XML Web 服务指定不受公共语言运行时标识符规则限制的 XML Web 服务的名称,该规则在 XML Web 服务的服务说明和服务帮助页中使用。

XML Web 服务应先更改其默认 XML 命名空间,然后再将其公开。 每个 XML Web 服务都需要一个唯一的 XML 命名空间来标识它,以便客户端应用程序能够将其与 Web 上的其他服务区分开来。 http://tempuri.org/ 可用于正在开发的 XML Web 服务,但已发布的 XML Web 服务应使用更永久的命名空间。

XML Web 服务应由你控制的 XML 命名空间标识。 例如,可以使用公司的 Internet 域名作为 XML 命名空间的一部分。 尽管许多 XML Web 服务 XML 命名空间看起来像 URL,但它们无需指向 Web 上的实际资源。 (XML Web 服务 XML 命名空间为 URI。) 对于使用 ASP.NET 创建的 XML Web 服务,可以使用 属性更改 Namespace 默认 XML 命名空间。

有关使用特性的详细信息,请参阅 特性

构造函数

WebServiceAttribute()

初始化 WebServiceAttribute 类的新实例。

字段

DefaultNamespace

Namespace 属性的默认值。 此字段为常数。

属性

Description

XML Web services 的描述性消息。

Name

获取或设置 XML Web services 的名称。

Namespace

获取或设置用于 XML Web services 的默认 XML 命名空间。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅