次の方法で共有


WebMethodAttribute コンストラクタ (Boolean, TransactionOption)

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

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

構文

'宣言
Public Sub New ( _
    enableSession As Boolean, _
    transactionOption As TransactionOption _
)
'使用
Dim enableSession As Boolean
Dim transactionOption As TransactionOption

Dim instance As New WebMethodAttribute(enableSession, transactionOption)
public WebMethodAttribute (
    bool enableSession,
    TransactionOption transactionOption
)
public:
WebMethodAttribute (
    bool enableSession, 
    TransactionOption transactionOption
)
public WebMethodAttribute (
    boolean enableSession, 
    TransactionOption transactionOption
)
public function WebMethodAttribute (
    enableSession : boolean, 
    transactionOption : TransactionOption
)
適用できません。

パラメータ

  • enableSession
    XML Web サービス メソッドに対してセッション状態が有効かどうかを初期化します。
  • transactionOption
    XML Web サービス メソッドのトランザクション サポートを初期化します。

解説

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 Server 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

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

WebMethodAttribute クラス
WebMethodAttribute メンバ
System.Web.Services 名前空間