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

<AttributeUsageAttribute(AttributeTargets.Method)> _ Public NotInheritable Class WebMethodAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Method)] public sealed class WebMethodAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method)] public ref class WebMethodAttribute sealed : public 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.Attribute
System.Web.Services.WebMethodAttribute


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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