WCF Tutorial | Transaction propagation
In WCF, transaction can be propagated across service boundary. This enables
service to participate in a client transaction and it includes multiple services
in same transaction, Client itself will act as service or client.
We can specify whether or not client transaction is propagated to service by
changing Binding and operational contract configuration
Even after enabling transaction flow does not mean that the service wants to use
the clientâ€™s transaction in every operation. We need to specify the
â€œTransactionFlowAttributeâ€ in operational contract to enable transaction flow.
public interface IService
int Add(int a, int b);
int Subtract(int a, int b);
Note: TransactionFlow can be enabled only at the operation level not
at the service level.
|Client cannot propagate its transaction to service even client has transaction
||Service will allow to flow client transaction.
It is not necessary that
service to use client transaction.
||If service disallows at binding level, client also should disable at binding
level else error will be occurred.
||Both Service and client must use transaction aware binding
||InvalidOperationException will be throw when serice binding disables at binding
FaultException will be thrown when client disable at its binding
- 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.