Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

WCF Transactions

on

  • 3,437 views

In-depth presentation about Transactions in WCF

In-depth presentation about Transactions in WCF

Statistics

Views

Total Views
3,437
Views on SlideShare
3,437
Embed Views
0

Actions

Likes
2
Downloads
140
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Transactions are necessary when two or more activities must be coordinated as a single operation, ensuring that the system is always left in a consistent state. The only two viable options are to complete all activities successfully or to leave the system as it was before initiating either activity.
  • The System.Transactions namespace is introduced with the .NET Framework 2.0 By default, what this block of code does is construct a new transaction, or join an existing transaction if one already exists by an upstream caller.
  • The Microsoft Distributed Transaction Coordinator (DTC) is a transaction manager that is able to coordinate resource managers that span application domain, process, and machine boundaries on the same network.With .NET 2.0, the LTM will first promote to KTM based on the conditions discussed in the previous section but will promote to DTC if any of the following conditions are met:
  • Configure DTC SecurityClick Start, click Run, type dcomcnfg and then click OK to open Component Services.Enable Network DTC Access.For the most secure results, enable mutual authentication for inbound or outbound communication.For testing purposes, you may disable authentication initially. If authentication is required, certificates must be configured for WS-AT
  • 2. Then, from the WS-AT tab of the DTCEnable WS-AtomicTransaction network support.First, you must add the snap-in using the following command-line instruction:Regasm.exe /codebase wsatui.dllC:WindowsMicrosoft.NETFramework64v2.0.50727Regasm.exe /codebase "c:Program FilesMicrosoft SDKsWindowsv6.0ABinx64wsatui.dll" Once this is done, you'll be able to see a WS-AT tab added to the DTC properties dialog This is where you will enable WS-AT support on the machine.Configure the HTTPS port to be used.Select an endpoint certificate and be sure that this certificate matches the machine name.
  • A service-oriented enterprise system typically includes many tiers, including clients, services, business components, data access tiers, and of course the actual data store that usually includes stored procedures invoked by the data access tier. Transactions can be initiated at any of these tiers, depending on the application scenario.Figure 6-13. Transactions initiated at the (A) stored procedure; (B) data access tier; (C) business tier; (D) client (crossing service boundaries)

WCF Transactions WCF Transactions Presentation Transcript

  • 27 April, 2009
    WCF Transactions
    by Tom Pester
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    2
    ACID
    Transactions must have the ACID properties.
    ACID stands for:
    • Atomic
    • Consistent
    • Isolated
    • Durable
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    3
    Two-phase commit protocol
    Phase 1
    The coordinator asks each resource manager to prepare to commit.
    Each resource manager responds (votes) to commit or abort the transaction.
    The coordinator collects all votes and makes a decision to commit or abort the entire transaction.
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    4
    Two-phase commit protocol
    Phase 2
    The coordinator asks each resource manager to commit or abort based on this decision.
    If the resource manager is asked to commit, it acknowledges completion of the activity. If asked to abort, it rolls back the activity.
    The coordinator waits for acknowledgment from all resource managers that the transaction was successfully committed.
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    5
    TransactionScope
    using (TransactionScope scope = new TransactionScope( ))
    {
    Operation1( );
    Operation2( );
     
    scope.Complete( );
    }
     
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    6
    Lightweight Transaction Manager
    Any number of volatile resource managers can be enlisted.
    Only a single durable resource manager can be enlisted.
    No application domain or process boundaries can be crossed.
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    7
    Kernel Transaction Manager
    Windows Vista introduced the Kernel Transaction Manager (KTM) to manage the resource managers associated with its Transactional Registry (TxR) and its transaction filesystem, called Transactional NTFS (TxF).
    When the downstream code within a TransactionScope enlists one of these resource managers, the LTM is promoted to KTM automatically.
    • Any number of volatile resource managers can be enlisted.
    • Only a single durable or kernel resource manager can be enlisted.
    • No application domain or process boundaries can be crossed.
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    8
    Distributed Transaction Coordinator
    • An application, process, or machine boundary is crossed.
    • More than one durable resource manager is enlisted
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    9
    WS-AtomicTransaction and WS-Coordination protocols
    WS-AtomicTransaction (WS-AT) and WS-Coordination (WS-COOR) are interoperable protocols that enable message-based distributed transactions over HTTP and across platform boundaries
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    10
    Enabling WS-AT
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    11
    Regasm.exe /codebase wsatui.dll
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    12
    Transactions and System Tiers
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    13
    Configuring WCF Transactions
    Transaction flow between clients and services is a function of
    • the binding configuration,
    • the service contract requirements
    • and the behavior of the service operation being invoked.
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    14
    Enabling transaction flow
    For a client transaction to flow across a service boundary, the binding must support transaction flow, which immediately limits you to one of these standard bindings: NetNamedPipeBinding
    • NetTcpBinding
    • WSHttpBinding,
    • WSDualHttpBinding
    • and WSFederationHttpBinding.
    <wsHttpBinding>
    <binding name="wsHttpTxTransactionFlow="true" />
    </wsHttpBinding>
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    15
    Transaction flow options
    The TransactionFlowAttribute
    • NotAllowed
    • Mandatory
    • Allowed
    [ServiceContract()]
    public interface ICountersService
    {
    [OperationContract]
    [TransactionFlow(TransactionFlowOption.Allowed)]
    void ResetCounters( );
     
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    16
    Service operations and transactions
    Although the TransactionFlowOption does influence the presence of a client transaction, it does not guarantee that a service operation will use the transaction.
    In the implementation of a service contract, each operation must opt-in to support transactions. TransactionScopeRequired property of the OperationBehaviorAttribute
    [OperationBehavior(TransactionScopeRequired=true)]
    public void ResetCounters( )
    {...}
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    17
    TransactionScopeRequired
    When set to false, which is the default setting, the service will never join a client transaction, nor will it automatically create a new transaction. That means that if the service code requires a transaction, it would have to do so manually using a TransactionScope block.
    When set to true, if a client transaction is flowed to the service, the service operation will join that transaction. If a client transaction is not flowed, a new transaction is created for the service operation to execute in.
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    18
    DistributedIdentifier
    An indicator that the service is participating in the client transaction is when the DistributedIdentifier of the current transaction is set:
    Transaction.Current.TransactionInformation.DistributedIdentifier
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    19
    TransactionAutoComplete
    Another property of the OperationBehaviorAttribute that affects how transactions are handled is the TransactionAutoComplete property. By default, this property is set to true, which means that the consistency bit is set to true automatically if no exceptions are thrown
    [OperationBehavior(TransactionScopeRequired=true,TransactionAutoComplete=false)]
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    20
    Controlling IsolationLevel
    The System.Transactions namespace defines an IsolationLevel enumeration that defines the following isolation options
    • Chaos
    • ReadCommitted
    • ReadUncommitted
    • RepeatableRead
    • Serializable
    • Snapshot
    • Unspecified
    The last of these settings, Unspecified, is the default.
  • 27 April, 2009
    WCF Transactions, by Tom Pester
    21
    TransactionOptions
    TransactionOptions options = new TransactionOptions( );options.IsolationLevel = IsolationLevel.Serializable;
    using (TransactionScope scope = new
    TransactionScope(TransactionScopeOption.Required, options))
    {
    m_proxy.SetCounter1(int.Parse(this.txtCounter.Text));
    m_proxy.SetCounter2(int.Parse(this.txtCounter.Text));
    scope.Complete( );
    }
  • 22
    WCF Transactions, by Tom Pester
    27 April, 2009