Visual Studio 2008: Windows Communication Foundation
Visual Studio 2008: Windows Communication Foundation
Visual Studio 2008: Windows Communication Foundation
Windows®
Communication
Foundation
Module 9: Implementing Transactions
• Overview of Transactions in a Service-Oriented Application
• Coordinating Transactions
• Transaction Context
• Distributed Transactions
My vote
Resource
Commit/Abort Manager Message Queue
Enlist
Vote?
My vote
Resource
Commit/Abort Manager Database
Enlist
Vote?
My vote
Resource
Commit/Abort Manager Mainframe
Transaction Context
WS-Coordination WS-AtomicTransaction
(WS-COOR) (WS-AT)
<bindings>
<wsHttpBinding>
<binding name = "BankExtranet" transactionFlow = "true"
transactionProtocol="WSAtomicTransactionOctober2004"/>
</wsHttpBinding>
</bindings>
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
void Transfer(string sourceAccount,
string targetAccount,
decimal amount);
[ServiceBehavior(TransactionIsolationLevel=
IsolationLevel.RepeatableRead) ]
public class BankService : IBank
{
... Chaos
} ReadCommitted
ReadUncommitted
RepeatableRead
Serializable
Snapshot
Unspecified
Controlling Transactions on Service Operations
[OperationBehavior(TransactionScopeRequired=true)]
void Transfer(string sourceAccount,
string targetAccount,
decimal amount)
{
...
}
TransactionScopeRequired on OperationBehavior
Must be set to true to propagate an existing transaction
Defaults to true
Demonstration: Automatic Transaction Initiation
In this demonstration, you will see how to:
• Apply transactional attributes to control the availability of
transactions in a WCF service operation
• Start a transaction when an operation is invoked
Notes Page Over-flow Slide. Do Not Print Slide.
See Notes pane.
Lesson: Enabling the Flow of Transactions From
Client to Service
• Configuring a Client to Propagate Transactions
<client>
<endpoint address="http://localhost:8080/BankService"
binding="wsHttpBinding"
bindingConfiguration="BankServiceWSBinding"
contract="IBank"/>
</client>
<bindings>
<wsHttpBinding>
<binding name="BankServiceWSBinding"
transactionFlow="true"
...
</wsHttpBinding>
</bindings>
Starting a Transaction on the Client
Use System.Transactions.TransactionScope:
• Can set options in constructor if desired
• Call Complete method to try and commit the transaction
scope.Complete();
}
Read session state at start of method and write back at end so that
it becomes part of the transaction
Logon information
Password Pa$$w0rd
• Best Practices
Course Evaluation