TransactionFlowOption Enumeración
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Una enumeración que se utiliza con TransactionFlowAttribute para especificar la directiva de flujo de transacción para una operación de servicio.
public enum class TransactionFlowOption
public enum TransactionFlowOption
type TransactionFlowOption =
Public Enum TransactionFlowOption
- Herencia
Campos
Allowed | 1 | Se puede realizar el flujo de la transacción. |
Mandatory | 2 | Se debe realizar el flujo de la transacción. |
NotAllowed | 0 | No se debería realizar el flujo de una transacción. Este es el valor predeterminado. |
Ejemplos
El ejemplo de código siguiente muestra el uso de esta enumeración junto con la clase TransactionFlowOption en el nivel de la operación.
using System;
using System.ServiceModel;
using System.Transactions;
namespace Microsoft.WCF.Documentation
{
[ServiceContract(
Namespace="http://microsoft.wcf.documentation",
SessionMode=SessionMode.Required
)]
public interface IBehaviorService
{
[OperationContract]
string TxWork(string message);
}
// Note: To use the TransactionIsolationLevel property, you
// must add a reference to the System.Transactions.dll assembly.
/* The following service implementation:
* -- Processes messages on one thread at a time
* -- Creates one service object per session
* -- Releases the service object when the transaction commits
*/
[ServiceBehavior(
ConcurrencyMode=ConcurrencyMode.Single,
InstanceContextMode=InstanceContextMode.PerSession,
ReleaseServiceInstanceOnTransactionComplete=true
)]
public class BehaviorService : IBehaviorService, IDisposable
{
Guid myID;
public BehaviorService()
{
myID = Guid.NewGuid();
Console.WriteLine(
"Object "
+ myID.ToString()
+ " created.");
}
/*
* The following operation-level behaviors are specified:
* -- The executing transaction is committed when
* the operation completes without an
* unhandled exception
* -- Always executes under a flowed transaction.
*/
[OperationBehavior(
TransactionAutoComplete = true,
TransactionScopeRequired = true
)]
[TransactionFlow(TransactionFlowOption.Mandatory)]
public string TxWork(string message)
{
// Do some transactable work.
Console.WriteLine("TxWork called with: " + message);
// Display transaction information.
TransactionInformation info = Transaction.Current.TransactionInformation;
Console.WriteLine("The distributed tx ID: {0}.", info.DistributedIdentifier);
Console.WriteLine("The tx status: {0}.", info.Status);
return String.Format("Hello. This was object {0}.",myID.ToString()) ;
}
public void Dispose()
{
Console.WriteLine(
"Service "
+ myID.ToString()
+ " is being recycled."
);
}
}
}
Imports System.ServiceModel
Imports System.Transactions
Namespace Microsoft.WCF.Documentation
<ServiceContract(Namespace:="http://microsoft.wcf.documentation", SessionMode:=SessionMode.Required)> _
Public Interface IBehaviorService
<OperationContract> _
Function TxWork(ByVal message As String) As String
End Interface
' Note: To use the TransactionIsolationLevel property, you
' must add a reference to the System.Transactions.dll assembly.
' The following service implementation:
' * -- Processes messages on one thread at a time
' * -- Creates one service object per session
' * -- Releases the service object when the transaction commits
'
<ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Single, InstanceContextMode:=InstanceContextMode.PerSession, _
ReleaseServiceInstanceOnTransactionComplete:=True)> _
Public Class BehaviorService
Implements IBehaviorService, IDisposable
Private myID As Guid
Public Sub New()
myID = Guid.NewGuid()
Console.WriteLine("Object " & myID.ToString() & " created.")
End Sub
'
' * The following operation-level behaviors are specified:
' * -- The executing transaction is committed when
' * the operation completes without an
' * unhandled exception
' * -- Always executes under a flowed transaction.
'
<OperationBehavior(TransactionAutoComplete:=True, TransactionScopeRequired:=True), TransactionFlow(TransactionFlowOption.Mandatory)> _
Public Function TxWork(ByVal message As String) As String Implements IBehaviorService.TxWork
' Do some transactable work.
Console.WriteLine("TxWork called with: " & message)
' Display transaction information.
Dim info As TransactionInformation = Transaction.Current.TransactionInformation
Console.WriteLine("The distributed tx ID: {0}.", info.DistributedIdentifier)
Console.WriteLine("The tx status: {0}.", info.Status)
Return String.Format("Hello. This was object {0}.", myID.ToString())
End Function
Public Sub Dispose() Implements IDisposable.Dispose
Console.WriteLine("Service " & myID.ToString() & " is being recycled.")
End Sub
End Class
End Namespace
Comentarios
Esta enumeración se utiliza para crear una instancia de la clase TransactionFlowAttribute, que se utiliza para marcar un método de contrato de servicio con objeto de indicar su directiva de flujo de transacción.