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 コンストラクタ ()
アセンブリ: 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 コンストラクタのページへのリンク