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 コンストラクタ ()
アセンブリ: System.Web.Services (system.web.services.dll 内)


<%@ 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> _ Public Function GetMachineName() As String Return Server.MachineName End Function End Class

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 コンストラクタ (Boolean, TransactionOption)
アセンブリ: System.Web.Services (system.web.services.dll 内)

Dim enableSession As Boolean Dim transactionOption As TransactionOption Dim instance As New WebMethodAttribute(enableSession, transactionOption)
public function WebMethodAttribute ( enableSession : boolean, transactionOption : TransactionOption )

HTTP プロトコルの状態のない性質のため、Web サービス呼び出しは、トランザクションのルートにだけなることができます。したがって、次の 2 つの設定は等価で、それぞれの呼び出しが新しいトランザクションを作成します。
[WebMethod(TransactionOption = TransactionOption.Required)] [WebMethod(TransactionOption = TransactionOption.RequiresNew)]
また、次のすべての設定は等価で、トランザクションがサポートされていないことを意味します。
[WebMethod] // TransactionOption.Disabled is the default [WebMethod(TransactionOption = TransactionOption.Disabled)] [WebMethod(TransactionOption = Transaction.NotSupported)] [WebMethod(TransactionOption = Transaction.Supported)]

<%@ WebService Language="VB" Class="Bank"%> <%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %> Imports System Imports System.Web.Services Imports System.EnterpriseServices Public Class Bank Inherits WebService <WebMethod(True,TransactionOption.RequiresNew)> _ Public Sub Transfer(Amount As Long, AcctNumberTo As Long, _ AcctNumberFrom As Long) Dim objBank As New MyCOMObject() If objBank.GetBalance(AcctNumberFrom) < Amount Then ' Explicitly end the transaction. ContextUtil.SetAbort() Else ' The Credit and Debit methods explictly determine, in their ' own code, whether to commit or end the transaction. objBank.Credit(Amount, AcctNumberTo) objBank.Debit(Amount, AcctNumberFrom) End If End Sub End Class
<%@ WebService Language="C#" Class="Bank"%> <%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %> using System; using System.Web.Services; using System.EnterpriseServices; public class Bank : WebService { [ WebMethod(true,TransactionOption.RequiresNew) ] public void Transfer(long Amount, long AcctNumberTo, long AcctNumberFrom) { MyCOMObject objBank = new MyCOMObject(); if (objBank.GetBalance(AcctNumberFrom) < Amount ) // Explicitly end the transaction. ContextUtil.SetAbort(); else { // The Credit and Debit methods explictly determine, in their // own code, whether to commit or end the transaction. objBank.Credit(Amount, AcctNumberTo); objBank.Debit(Amount, AcctNumberFrom); } } }

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


WebMethodAttribute コンストラクタ

名前 | 説明 |
---|---|
WebMethodAttribute () | WebMethodAttribute クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
WebMethodAttribute (Boolean) | WebMethodAttribute クラスの新しいインスタンスを初期化します。 |
WebMethodAttribute (Boolean, TransactionOption) | WebMethodAttribute クラスの新しいインスタンスを初期化します。 |
WebMethodAttribute (Boolean, TransactionOption, Int32) | WebMethodAttribute クラスの新しいインスタンスを初期化します。 |
WebMethodAttribute (Boolean, TransactionOption, Int32, Boolean) | WebMethodAttribute クラスの新しいインスタンスを初期化します。 |

WebMethodAttribute コンストラクタ (Boolean, TransactionOption, Int32, Boolean)
アセンブリ: System.Web.Services (system.web.services.dll 内)

Public Sub New ( _ enableSession As Boolean, _ transactionOption As TransactionOption, _ cacheDuration As Integer, _ bufferResponse As Boolean _ )
Dim enableSession As Boolean Dim transactionOption As TransactionOption Dim cacheDuration As Integer Dim bufferResponse As Boolean Dim instance As New WebMethodAttribute(enableSession, transactionOption, cacheDuration, bufferResponse)
public WebMethodAttribute ( bool enableSession, TransactionOption transactionOption, int cacheDuration, bool bufferResponse )
public: WebMethodAttribute ( bool enableSession, TransactionOption transactionOption, int cacheDuration, bool bufferResponse )
public WebMethodAttribute ( boolean enableSession, TransactionOption transactionOption, int cacheDuration, boolean bufferResponse )
public function WebMethodAttribute ( enableSession : boolean, transactionOption : TransactionOption, cacheDuration : int, bufferResponse : boolean )

HTTP プロトコルの状態のない性質のため、Web サービス呼び出しは、トランザクションのルートのみになることができます。したがって、次の 2 つの設定は等価で、それぞれの呼び出しが新しいトランザクションを作成します。
[WebMethod(TransactionOption = TransactionOption.Required)] [WebMethod(TransactionOption = TransactionOption.RequiresNew)]
また、次のすべての設定は等価で、トランザクションがサポートされていないことを意味します。
[WebMethod] // TransactionOption.Disabled is the default [WebMethod(TransactionOption = TransactionOption.Disabled)] [WebMethod(TransactionOption = Transaction.NotSupported)] [WebMethod(TransactionOption = Transaction.Supported)]

<%@WebService Class="Streaming" language="VB"%> <%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %> Imports System Imports System.IO Imports System.Collections Imports System.Xml.Serialization Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.EnterpriseServices Public Class Streaming <WebMethod(True,TransactionOption.NotSupported,60,False)> _ Public Function GetTextFile(filename As String ) As TextFile Return New TextFile(filename) End Function <WebMethod> _ Public Sub CreateTextFile(contents As TextFile) contents.Close() End Sub End Class Public Class TextFile Public filename As String Private readerWriter As TextFileReaderWriter Public Sub New() End Sub Public Sub New(filename As String) Me.filename = filename End Sub <XmlArrayItem("line")> _ Public ReadOnly Property contents As TextFileReaderWriter Get readerWriter = New TextFileReaderWriter(filename) Return readerWriter End Get End Property Public Sub Close() If Not (readerWriter Is Nothing) Then readerWriter.Close() End If End Sub End Class Public Class TextFileReaderWriter Implements IEnumerable Public Filename As String Private writer As StreamWriter Public Sub New() End Sub Public Sub New(myfilename As String ) Filename = myfilename End Sub Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator Dim reader As StreamReader = New StreamReader(Filename) Return New TextFileEnumerator(reader) End Function Public Sub Add(line As String) If (writer Is Nothing) Then writer = New StreamWriter(Filename) End If writer.WriteLine(line) End Sub Public Sub Add(obj as Object) End Sub Public Sub Close() If Not (writer Is Nothing) Then writer.Close() End Sub End Class Public Class TextFileEnumerator Implements IEnumerator Private currentLine As String Private reader As StreamReader Public Sub New(reader As StreamReader) Me.reader = reader End Sub Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext currentLine = reader.ReadLine() If (currentLine Is Nothing) Then reader.Close() Return False Else Return True End If End Function Public Sub Reset() Implements IEnumerator.Reset reader.BaseStream.Position = 0 End Sub ReadOnly Property Current As object Implements IEnumerator.Current Get Return CurrentLine End Get End Property End Class
<%@WebService class="Streaming" language="C#"%> <%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %> using System; using System.IO; using System.Collections; using System.Xml.Serialization; using System.Web.Services; using System.Web.Services.Protocols; using System.EnterpriseServices; public class Streaming { [WebMethod(true,TransactionOption.NotSupported,60,false)] public TextFile GetTextFile(string filename) { return new TextFile(filename); } [WebMethod] public void CreateTextFile(TextFile contents) { contents.Close(); } } public class TextFile { public string filename; private TextFileReaderWriter readerWriter; public TextFile() { } public TextFile(string filename) { this.filename = filename; } [XmlArrayItem("line")] public TextFileReaderWriter contents { get { readerWriter = new TextFileReaderWriter(filename); return readerWriter; } } public void Close() { if (readerWriter != null) readerWriter.Close(); } } public class TextFileReaderWriter : IEnumerable { public string Filename; private StreamWriter writer; public TextFileReaderWriter() { } public TextFileReaderWriter(string filename) { Filename = filename; } public TextFileEnumerator GetEnumerator() { StreamReader reader = new StreamReader(Filename); return new TextFileEnumerator(reader); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Add(string line) { if (writer == null) writer = new StreamWriter(Filename); writer.WriteLine(line); } public void Close() { if (writer != null) writer.Close(); } } public class TextFileEnumerator : IEnumerator { private string currentLine; private StreamReader reader; public TextFileEnumerator(StreamReader reader) { this.reader = reader; } public bool MoveNext() { currentLine = reader.ReadLine(); if (currentLine == null) { reader.Close(); return false; } else return true; } public void Reset() { reader.BaseStream.Position = 0; } public string Current { get { return currentLine; } } object IEnumerator.Current { get { return Current; } } }

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


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


<%@ WebService Language="VB" Class="Util" %> Imports System.Web.Services Public Class Util Inherits WebService <WebMethod(True)> _ Public Function SessionHitCounter() As Integer If Session("HitCounter") Is Nothing Then Session("HitCounter") = 1 Else Session("HitCounter") = CInt(Session("HitCounter")) + 1 End If Return CInt(Session("HitCounter")) End Function End Class
<%@ WebService Language="C#" Class="Util" %> using System.Web.Services; public class Util: WebService { [ WebMethod(true)] public int SessionHitCounter() { if (Session["HitCounter"] == null) { Session["HitCounter"] = 1; } else { Session["HitCounter"] = ((int) Session["HitCounter"]) + 1; } return ((int) Session["HitCounter"]); } }

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


WebMethodAttribute コンストラクタ (Boolean, TransactionOption, Int32)
アセンブリ: System.Web.Services (system.web.services.dll 内)

Public Sub New ( _ enableSession As Boolean, _ transactionOption As TransactionOption, _ cacheDuration As Integer _ )
Dim enableSession As Boolean Dim transactionOption As TransactionOption Dim cacheDuration As Integer Dim instance As New WebMethodAttribute(enableSession, transactionOption, cacheDuration)
public WebMethodAttribute ( bool enableSession, TransactionOption transactionOption, int cacheDuration )
public: WebMethodAttribute ( bool enableSession, TransactionOption transactionOption, int cacheDuration )
public WebMethodAttribute ( boolean enableSession, TransactionOption transactionOption, int cacheDuration )
public function WebMethodAttribute ( enableSession : boolean, transactionOption : TransactionOption, cacheDuration : int )

HTTP プロトコルの状態のない性質のため、Web サービス呼び出しは、トランザクションのルートにだけなることができます。したがって、次の 2 つの設定は等価で、それぞれの呼び出しが新しいトランザクションを作成します。
[WebMethod(TransactionOption = TransactionOption.Required)] [WebMethod(TransactionOption = TransactionOption.RequiresNew)]
また、次のすべての設定は等価で、トランザクションがサポートされていないことを意味します。
[WebMethod] // TransactionOption.Disabled is the default [WebMethod(TransactionOption = TransactionOption.Disabled)] [WebMethod(TransactionOption = Transaction.NotSupported)] [WebMethod(TransactionOption = Transaction.Supported)]

<%@ WebService Language="VB" Class="Counter" %> <%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %> Imports System.Web.Services Imports System Imports System.Web Imports System.EnterpriseServices Public Class Counter Inherits WebService <WebMethod(true,TransactionOption.NotSupported,60)> _ Public Function ServiceUsage() As Integer ' If the XML Web service has not been accessed, initialize it to 1. If Application("MyServiceUsage") Is Nothing Then Application("MyServiceUsage") = 1 Else ' Increment the usage count. Application("MyServiceUsage") = CInt(Application("MyServiceUsage")) + 1 End If ' Return the usage count. Return CInt(Application("MyServiceUsage")) End Function End Class
<%@ WebService Language="C#" Class="Counter" %> <%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %> using System.Web.Services; using System; using System.Web; using System.EnterpriseServices; public class Counter : WebService { [ WebMethod(true,TransactionOption.NotSupported,60) ] public int ServiceUsage() { // If the XML Web service has not been accessed, initialize it to 1. if (Application["MyServiceUsage"] == null) { Application["MyServiceUsage"] = 1; } else { // Increment the usage count. Application["MyServiceUsage"] = ((int) Application["MyServiceUsage"]) + 1; } // Return the usage count. return (int) Application["MyServiceUsage"]; } }

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


WebMethodAttribute プロパティ

名前 | 説明 | |
---|---|---|
![]() | BufferResponse | この要求に対する応答がバッファリングされるどうかを取得または設定します。 |
![]() | CacheDuration | 応答をキャッシュ内に保持する秒数を取得または設定します。 |
![]() ![]() | EnableSession | XML Web サービス メソッドに対してセッション状態が有効かどうかを示します。 |
![]() ![]() | TransactionOption | XML Web サービス メソッドのトランザクション サポートを示します。 |
![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。) |

WebMethodAttribute メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

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


名前 | 説明 | |
---|---|---|
![]() | BufferResponse | この要求に対する応答がバッファリングされるどうかを取得または設定します。 |
![]() | CacheDuration | 応答をキャッシュ内に保持する秒数を取得または設定します。 |
![]() ![]() | EnableSession | XML Web サービス メソッドに対してセッション状態が有効かどうかを示します。 |
![]() ![]() | TransactionOption | XML Web サービス メソッドのトランザクション サポートを示します。 |
![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

Weblioに収録されているすべての辞書からWebMethodAttributeを検索する場合は、下記のリンクをクリックしてください。

- WebMethodAttributeのページへのリンク