.NET Framework クラス ライブラリ
WebMethodAttribute クラス

更新 : 2007 年 11 月

ASP.NET で作成された XML Web サービス内でこの属性をメソッドに追加すると、リモートの Web クライアントから該当するメソッドを呼び出すことができます。このクラスは継承できません。

名前空間 :  System.Web.Services
アセンブリ :  System.Web.Services (System.Web.Services.dll 内)

構文

Visual Basic (宣言)
<AttributeUsageAttribute(AttributeTargets.Method)> _
Public NotInheritable Class WebMethodAttribute _
    Inherits Attribute
Visual Basic (使用法)
Dim instance As WebMethodAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Method)]
public sealed class WebMethodAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Method)]
public ref class WebMethodAttribute sealed : public Attribute
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Method) */
public final class WebMethodAttribute extends Attribute
JScript
public final class WebMethodAttribute extends Attribute
解説

この属性が設定されているクラス内のメソッドは、XML Web サービス メソッドと呼ばれます。このメソッドとクラスはパブリックとして指定し、ASP.NET Web アプリケーション内部で実行する必要があります。


WebMethodAttribute が設定されているためメソッド GetMachineName を Web 経由でリモートから呼び出すことができる例を次に示します。GetUserNamepublic ですが、WebMethodAttribute が設定されていないためリモートから呼び出すことはできません。

Visual Basic
<%@ 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

C#
<%@ 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
参照

参照

タグ :


Page view tracker