WCF distributed Development Step by step: WCF transaction mechanism (Transaction) and distributed transaction programming

Source: Internet
Author: User
Tags data structures

Today we continue to learn the WCF distributed development step-by-Step Series 12: WCF transaction mechanism (Transaction) and distributed transaction programming. As we all know, in the process of application system development, the transaction is an important concept. It is an important mechanism to guarantee the reliability of data and service. As a development platform for service-oriented applications, WCF also provides support for the programming model of things.. NET 2.0 provides a System.Transactions class to develop transactional applications. Also, WCF supports transactional attributes, what is the WCF transaction mechanism, and what does it have to do with Microsoft's existing technologies such as the Microsoft Distributed Transaction Coordinator (MSDTC)? What is the difference between the Enterpise services (Microsoft Application Server technology) and COM + 's things mechanism, this article will be detailed, today we will learn about WCF transaction processing mechanism and how to use this feature in the project. The full text of the structure "1" Transaction Concept "2" Transaction attributes, "3" Transaction Protocol, "4" transaction manager, "5" Transaction Programming, "6" Sample code explanation, "7" summary.

The transaction mechanism provided by WCF. In fact, in addition to using the existing. NET framework provided by the transaction mechanism, but also based on their own needs to expand. The question is not difficult to understand. The WCF programming model tells us that WCF applications typically include customer systems, WCF service systems. In addition to being able to implement transactions through the transaction mechanisms within RDBMS such as SQL Server, you can use the System.Transactions classes provided by NET 2.0 to implement transactions. This transaction exists only on the server or client side. WCF requirements typically implement transaction constraints that operate between clients and multiple services, which is often called distributed transactions. WCF did not fully redesign a set of frameworks to implement distributed transactions. Here it uses Microsoft's early technology MSDTC distributed Transaction Coordinator to implement the distributed transaction. Here we will also introduce.

First, let's review the business's gratitude:

"1" Transaction concept:

What is a business? Actually, this thing. A concept in a database system. A transaction (Transaction) is the basic unit of concurrent control. The so-called transaction, it is a sequence of operations, these operations are either executed, or not executed, it is an indivisible unit of work.

For example, a bank transfer: typically includes two actions:

(1) From an account number a deduction;

(2) Make another account B increase.

Both of these operations are either executed or not executed. In the banking system, the database system executes the relevant commands to accomplish both operations. A transaction is a unit that maintains data consistency in a database, ensuring data consistency at the end of each transaction. There is no error in the amount of the account. Ensure the correct completion of the transfer operation.

"2" Transaction properties:

Transactions also have their own characteristics. This is very familiar to everyone. believe that each database-related book will introduce the characteristics of the transaction acid. Transaction processing ensures that data-oriented resources are not permanently updated unless all operations within the transactional unit are completed successfully. By combining a set of related actions into a unit that is either fully successful or all failed, you can simplify error recovery and make your application more reliable. To be a transaction, a logical unit of work must satisfy the so-called acid (atomicity, consistency, isolation, and durability) attribute:

<1> Atomic nature:

The transaction must be an atomic unit of work, or all of its data modifications, or none of them executed. Typically, the operations associated with a transaction have common goals and are interdependent. A transaction is done or undone completely and without ambiguity. In the case of an error in any operation, the effect of all operations that make up the transaction must be undone, and the data should be rolled back to the previous state. For example, two operations in a transfer transaction, either full execution or full execution.

<2> Consistency:

When a transaction completes, you must keep all the data in a consistent state. In the related database, all rules must be applied to the modification of the transaction to preserve the integrity of all data. When a transaction ends, all internal data structures, such as a B-tree index or a two-way list, must be correct. Some of the responsibility for maintaining consistency rests with the application developer, who must ensure that all known integrity constraints are enforced by the application. For example, a account of 10000 yuan, B account 0 yuan, after the successful transfer. The total amount of account A and B remains unchanged. It's still 10000 yuan. It will not increase the total amount because of the successful transfer.

<3> Isolation:

Modifications made by concurrent transactions must be isolated from modifications made by any other concurrent transaction. The state that the data is in when the transaction views the data, either when another concurrent transaction modifies its previous state, or when another transaction modifies its state, the transaction does not view the data in the middle state. This is called serializable because it can reload the starting data and replay a series of transactions so that the state of the data at the end is the same as that of the original transaction. The highest isolation level is obtained when the transaction is serializable. At this level, the results obtained from a set of transactions that can be executed in parallel are the same as those obtained by running each transaction continuously. Serial execution transactions: the intermediate (possibly inconsistent) state of the data should not be exposed to all other transactions during the execution of a transaction.

Two concurrent transactions should not be able to manipulate the same data. A database management system usually uses locks to achieve isolation.

<4> Durability:

WCF supports distributed transactions, meaning that transactions can span service boundaries, processes, machines, networks, and exist between multiple clients and services. and the corresponding transaction data information dissemination and management of the protocol is different.

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.

Tags Index: