WebServiceAttribute 类

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

**命名空间:**System.Web.Services
**程序集:**System.Web.Services(在 system.web.services.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Interface)> _
Public NotInheritable Class WebServiceAttribute
    Inherits Attribute
用法
Dim instance As WebServiceAttribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface)] 
public sealed class WebServiceAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Interface)] 
public ref class WebServiceAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface) */ 
public final class WebServiceAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface) 
public final class WebServiceAttribute extends Attribute

备注

对于将要发布和执行的 XML Web services 来说,WebServiceAttribute 不是必需的。可以使用 WebServiceAttribute 为 XML Web services 指定不受公共语言运行库标识符(用于 XML Web services 的“服务说明”和“服务帮助”页)规则限制的名称。

XML Web services 在成为公共之前,应该更改其默认的 XML 命名空间。每个 XML Web services 都需要唯一的 XML 命名空间来标识它,以便客户端应用程序能够将它与网络上的其他服务区分开来。http://tempuri.org/ 可用于正在开发中的 XML Web services,

但是已发布的 XML Web services 应该使用更具永久性的命名空间。例如,可以将公司的 Internet 域名作为 XML 命名空间的一部分。虽然很多 XML Web services 的 XML 命名空间与 URL 很相似,但是,它们无需指向 Web 上的某一实际资源。(XML Web services 的 XML 命名空间是 URI。)对于使用 ASP.NET 创建的 XML Web services,可以使用 Namespace 属性更改默认的 XML 命名空间。

有关使用属性的更多信息,请参见 利用属性扩展元数据

示例

下面的示例将 WebServiceAttributeDescription 属性设置为“Common Server Variables”,并将 XML 命名空间设置为 https://www.microsoft.com/china。

<%@ WebService Language="VB" Class= "ServerVariables"%>
 
Imports System
Imports System.Web.Services

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

继承层次结构

System.Object
   System.Attribute
    System.Web.Services.WebServiceAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

WebServiceAttribute 成员
System.Web.Services 命名空间
WebService 类
WebMethodAttribute 类
SoapDocumentMethodAttribute
SoapDocumentServiceAttribute
SoapRpcMethodAttribute
SoapRpcServiceAttribute