WebMethodAttribute クラス

定義

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

public ref class WebMethodAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class WebMethodAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type WebMethodAttribute = class
    inherit Attribute
Public NotInheritable Class WebMethodAttribute
Inherits Attribute
継承
WebMethodAttribute
属性

次の例では、 メソッド GetMachineName は を持 WebMethodAttributeっているため、Web 全体でリモートで呼び出すことができます。 GetUserNameが であっても、 を持たないため、リモートでWebMethodAttributepublic呼び出すことはできません。

<%@ 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;
       }
    }
<%@ 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

注釈

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

コンストラクター

WebMethodAttribute()

WebMethodAttribute クラスの新しいインスタンスを初期化します。

WebMethodAttribute(Boolean)

WebMethodAttribute クラスの新しいインスタンスを初期化します。

WebMethodAttribute(Boolean, TransactionOption)

WebMethodAttribute クラスの新しいインスタンスを初期化します。

WebMethodAttribute(Boolean, TransactionOption, Int32)

WebMethodAttribute クラスの新しいインスタンスを初期化します。

WebMethodAttribute(Boolean, TransactionOption, Int32, Boolean)

WebMethodAttribute クラスの新しいインスタンスを初期化します。

プロパティ

BufferResponse

この要求に対する応答がバッファリングされるどうかを取得または設定します。

CacheDuration

応答をキャッシュ内に保持する秒数を取得または設定します。

Description

XML Web サービス メソッドを説明する説明メッセージ。

EnableSession

XML Web サービス メソッドに対してセッション状態が有効かどうかを示します。

MessageName

XML Web サービス メソッドへ渡されるデータ、および XML Web サービス メソッドから返されるデータ内で XML Web サービス メソッドに使用される名前。

TransactionOption

XML Web サービス メソッドのトランザクション サポートを示します。

TypeId

派生クラスで実装されると、この Attribute の一意の識別子を取得します。

(継承元 Attribute)

メソッド

Equals(Object)

このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。

(継承元 Attribute)
GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 Attribute)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください