Regarding transactions in WCF services, shall I use TransactionScope object in client side application that consumes the service or in the service code? Please explain why.
Regarding transactions in WCF services, shall I use TransactionScope object in client side application
Share
Making a service transaction aware means that if passed a transaction it will enlist in it
Whoever consumes the service, be it a client application or another service, must create a transaction (or already be running in a transaction flowed to them) for the service to enlist – hence they must call the service from within a TransactionScope (either explicitly or implicitly by having the transaction flowed to them).
If the operation is marked as TransactionFlow(TransactionFlowOption.Allowed) then the consumer does not have to have a transaction, but then the service will not execute in a flowed transation
If the operation is marked as TransactionFlow(TransactionFlowOption.Mandatory) then the client must flow a transaction, and assuming the other bits are aligned (OperationBehavior creates auto enlists, etc) then the operation will run in the same distributed transaction