WCF from theory to Practice (12): Business

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.