更新 : 2007 年 11 月
ASP.NET で作成された XML Web サービス内でこの属性をメソッドに追加すると、リモートの Web クライアントから該当するメソッドを呼び出すことができます。このクラスは継承できません。
名前空間 :
System.Web.Services アセンブリ :
System.Web.Services (System.Web.Services.dll 内)
<AttributeUsageAttribute(AttributeTargets.Method)> _
Public NotInheritable Class WebMethodAttribute _
Inherits Attribute
Dim instance As WebMethodAttribute
[AttributeUsageAttribute(AttributeTargets.Method)]
public sealed class WebMethodAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method)]
public ref class WebMethodAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */
public final class WebMethodAttribute extends Attribute
public final class WebMethodAttribute extends Attribute
この属性が設定されているクラス内のメソッドは、XML Web サービス メソッドと呼ばれます。このメソッドとクラスはパブリックとして指定し、ASP.NET Web アプリケーション内部で実行する必要があります。
WebMethodAttribute が設定されているためメソッド GetMachineName を Web 経由でリモートから呼び出すことができる例を次に示します。GetUserName は public ですが、WebMethodAttribute が設定されていないためリモートから呼び出すことはできません。
<%@ WebService Language="VB" Class="Util"%>
Imports System
Imports System.Web.Services
Public Class Util
Inherits WebService
Public Function GetUserName() As String
Return User.Identity.Name
End Function
<WebMethod(Description := "Obtains the Server Machine Name", _
EnableSession := True)> _
Public Function GetMachineName() As String
Return Server.MachineName
End Function
End Class
<%@ WebService Language="C#" Class="Util"%>
using System;
using System.Web.Services;
public class Util: WebService {
public string GetUserName() {
return User.Identity.Name;
}
[ WebMethod(Description="Obtains the Server Machine Name",
EnableSession=true)]
public string GetMachineName() {
return Server.MachineName;
}
}
System..::.Object
System..::.Attribute
System.Web.Services..::.WebMethodAttribute
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
.NET Framework
サポート対象 : 3.5、3.0、2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 3.5、2.0、1.0
参照