WebServiceAttribute クラス
アセンブリ: System.Web.Services (system.web.services.dll 内)

<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Interface)> _ Public NotInheritable Class WebServiceAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface)] public sealed class WebServiceAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Interface)] public ref class WebServiceAttribute sealed : public Attribute

WebServiceAttribute は、XML Web サービスを発行および実行するための必須クラスではありません。WebServiceAttribute を使用すると、XML Web サービスに対して、共通言語ランタイム識別子の規則によって制限されない名前を指定できます。この名前は、XML Web サービスのサービスの説明やサービス ヘルプ ページで使用されます。
XML Web サービスは、既定の XML 名前空間を変更してから公開する必要があります。クライアント アプリケーションが XML Web サービスを Web 上の他のサービスと区別できるように、各 XML Web サービスには、サービスを識別する固有の XML 名前空間が必要です。開発中の XML Web サービスには http://tempuri.org/ を使用できますが、発行された XML Web サービスではより永続的な名前空間を使用する必要があります。
XML Web サービスは、制御している XML 名前空間で識別する必要があります。たとえば、会社内のインターネット ドメイン名を XML 名前空間の一部として使用できます。多くの XML Web サービスの XML 名前空間は URL と似ていますが、XML 名前空間は Web 上の実際のリソースを指す必要はありません。XML Web サービスの XML 名前空間は URI です。ASP.NET で作成した XML Web サービスの場合、既定の XML 名前空間は Namespace プロパティを使用して変更できます。

WebServiceAttribute の Description プロパティを "Common Server Variables" に設定し、XML 名前空間を http://www.microsoft.com/japan に設定する例を次に示します。
<%@ 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
<%@ 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; } }

System.Attribute
System.Web.Services.WebServiceAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- WebServiceAttribute クラスのページへのリンク