The purpose of this article
By reading this article, you can understand the following knowledge
1 How do I implement a transaction in WCF?
2 to discuss the relevant knowledge of transaction isolation mode
3 What kind of resistance will the implementation of the transaction bring to our programming?
4) How does WCF implement distributed transactions with a single stroke?
5 code is not deceptive, using a bank deposit and withdrawal paradigm to walkthrough WCF transactions
This article is suitable for readers
This article is suitable for WCF beginners, before you learn this article, you'd better read the first few of WCF's series of articles from theory to practice
How do I implement a transaction in WCF?
Business is a difficult thing to achieve, but WCF can always transform the magic, it can through a simple declarative programming way, you can achieve distributed transactions, the following is to see to achieve this goal of the hero:
1) Transactionflowattribute: An attribute of the operation contract (OperationContractAttribute) that can indicate the transaction options (Operation) of the owning operation ( transactionflowoption).
2) Transactionflowoption: It is a parameter in the Transactionflowattribute constructor, an enumeration (enum), including three enumerated items notallowed: Transaction not allowed, default value Allowed: Allow a transaction, meaning that the transaction is dispensable; mandatory: Force a transaction, which means that the transaction is required.
3) TransactionAutoCompleteOnSessionClose: It is an attribute of the action behavior (OperationBehaviorAttribute) that is used to mark whether the service-side instance is automatically released after the transaction is completed. This attribute is closely related to the service object instance pattern, and should be used with caution, as described below.
4) Transactionisolationlevel: is also an attribute of the action behavior (OperationBehaviorAttribute) that indicates the transaction isolation method (Isolation Level). Includes 5 options: Any, Readuncommitted,readcommitted,repeatableread,serializable, the separation mode of the transaction related knowledge is more complex, left for the 2nd of the article will be specifically elaborated
5) TransactionTimeout: is also an attribute of the action behavior (OperationBehaviorAttribute) that indicates the timeout for the transaction, the default is TimeSpan.Zero, which means that it is not limited by the timeout period.:: OperationBehaviorAttribute: is also an attribute of the action behavior (OperationBehaviorAttribute) that indicates the Distributed Transaction option and, if set to true, must be in the transaction scope (Transaction Scorp) within.
With the use of the above several attributes, we can easily implement transactions and distributed transactions in WCF. The implementation method can refer to the code example