WCF Tutorial
www.Learn2Expert.net A new ASP.Net MVC 4, SSIS, Interview Q/A tutorial - Visit - www.Learn2Expert.net
Skip Navigation LinksHomeTransactionTransaction Mode No of Views: 46498

Transaction Mode

This article explains about the how to configure the service and client transaction mode in WCF service.

  • Client transaction – Transaction setting propagated or initiated from the client side
  • Server transaction – Transaction setting propagated or initiated from server side

Client/Server transaction mode:

This setting ensures that service uses the client’s transaction if possible or a server side transaction when the client does not have a transaction.

  1. Enable the TransactionFlow=true in binding configuration
  2. Set TransactionFlowOption.Allowed in the operation contract
  3. Set TransactionScopeRequired=true in the operation contract

Client transaction mode:

This settings ensures the service uses only the client’s transaction

  1. Enable the TransactionFlow=true in binding configuration
  2. Set TransactionFlowOption.Mandatory in the operation contract
  3. Set TransactionScopeRequired=true in the operation contract

Service transaction mode:

This seeing ensures that the service always has a transaction, separated from any transaction its client may or may not have.

  1. Disable the TransactionFlow=false in binding configuration
  2. Set TransactionFlowOption.NotAllowed in the operation contract
  3. Set TransactionScopeRequired=true in the operation contract

None transaction mode:

This setting ensures service does not use transaction

  1. Disable the TransactionFlow=false in binding configuration
  2. Set TransactionFlowOption.NotAllowed in the operation contract
  3. Set TransactionScopeRequired=false in the operation contract

Below table explains about the Transaction mode activation based on the binging, contract and behavior settings

Binding Transaction flow TransactionFlowOption TransactionScopeRequired Transaction mode
False Allowed False None
False Allowed True Service
False NotAllowed False None
False Allowed True Service
True Allowed False None
True Allowed True Client/Service
True Mandatory False None
True Mandatory True Client

Tips!

  • Always create the service with Interface->Implementation format, mention the contract in Interface.
  • Define the service in Class library and refer the class library in Host project. Don’t use service class in host project.
  • Change the instance mode to per call as default.
  • Always catch exception using try/catch block and throw exception using FaultException < T >.
  • Logging and Include exception should be enable while compiling the project in debug mode. While in production deployment disable the logging and Include exception details.