---
title: "Transaction in WCF"  
description: "In this post, I’m explaining transaction in WCF.  What is a transaction in WCF?The process contains multiple organizations and workflows involved. The"  
author: "priyanka kushwaha"  
published: 2015-03-19  
updated: 2018-02-21  
canonical: https://www.mindstick.com/blog/10844/transaction-in-wcf  
category: ".net"  
tags: ["wcf", "security", "wcf security"]  
reading_time: 3 minutes  

---

# Transaction in WCF

In this post, I’m explaining [transaction](https://www.mindstick.com/blog/175/transactions-in-database) in WCF.

\

##### What is a transaction in WCF?

The process contains multiple [organizations](https://yourviews.mindstick.com/view/84018/why-should-b2b-organizations-use-content-marketing) and workflows involved. The short running [transactions](https://www.mindstick.com/interview/864/explain-acid-rule-of-thumb-for-transactions) are operations related to business that is completed in few seconds. It contains some external dependencies. These scenarios are [known as](https://answers.mindstick.com/qa/35703/ricky-ponting-is-also-known-as-what) a transaction.

The behavior of the transactions is known as ACID transactions. The ACID transactions are as explained below:

1. Atomic: In atomic transactions, all the updates within the transaction are successful or are rolled back. No partial updates are allowed.

2. Consistent: After all the operations are completed, the data is validated to the business rules.

3. Isolated: When the user is executing an operation, no partial results can be viewed outside the transaction.

4. Durable: When the transaction is committed, the data is persisted to survive from the failures

##### Transaction type in WCF are:

1. Light weight

2. OLE transaction

3. WS-Atomic transaction,

Lightweight protocol: Under this protocol, transaction must be within a single AppDomain. There should not be any across calls for other AppDomains, so logically no client-service calls are allowed.

OLE transaction: The OLE transaction protocol is the standard for use with distributed transaction. This protocol works within the window [environment](https://yourviews.mindstick.com/view/308/need-to-create-a-supportive-work-environment-for-women) through Remote procedure calls. Under this protocol [communication](https://www.mindstick.com/articles/126321/5-fails-and-fixes-of-the-office-communication) through firewalls is now allowed and cross-platform

[Communications](https://www.mindstick.com/articles/44489/leased-lines-and-other-tools-for-business-communications) are also not allowed.

WS-Atomic transaction: WS-Atomic protocol is an [industry standard](https://answers.mindstick.com/qa/51696/what-is-thunderbolt-is-it-an-industry-standard-what-advantages-does-it-offer-are-there-any-disadvantages) that can be used over Http.

OLE is limited to computers running windows behind a firewall.

Transaction [Attributes](https://www.mindstick.com/articles/13105/2-attributes-that-make-your-odoo-ecommerce-theme-productive-and-engaging) in System.ServiceModel

- ServiceBehavior Attribute
- OperationBehavior Attribute
- Transaction Attribute

ServiceBehavior Attribute: The [ServiceBehavior] attribute has [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) that deal with handling and managing transactions.

- TransactionAutoCompleted: Specifies whether pending transactions are completed when the current session closed.
- TransactionIsolationLevel: Determines the isolation level of the transaction.
- TransactionTimeout: Specifies the period in which a transaction has to complete.

##### Example:

```
  [ServiceBehavior(TransactionAutoCompleteOnSessionClose = true, TransactionTimeout = "00:00:30", TransactionIsolationLevel=IsolationLevel.ReadCommitted)]    public class Service2 : IService2    {      public int InsertEmployee(Employee emp)        {                    }        public int DeleteEmployee(string EmpNo)        {        }        public Employee[] GetAllEmployee()        {        }         }        #endregion    }} 
```

OperationBehavior Attribute:

The [OperationBehavior] also has a coupled of properties related to transactions. The two properties are:

\
TransactionAutoComplete: Specifies that transactions will be auto-completed if no eTransactionScopeRequired: Specifies whether the associate method requires a transaction.

##### Example:

```
  [ServiceBehavior(TransactionAutoCompleteOnSessionClose = true, TransactionTimeout = "00:00:30", TransactionIsolationLevel=IsolationLevel.ReadCommitted)]    public class Service2 : IService2    {      [OperationBehavior(TransactionAutoComplete=true,TransactionScopeRequired=true)]            [TransactionFlow(TransactionFlowOption.NotAllowed)]      public int InsertEmployee(Employee emp)      {                  }      public int DeleteEmployee(string EmpNo)      {      }      public Employee[] GetAllEmployee()      {      }             #endregion    }}
```

TransactionFlowAttribute

The [TransactionFlow attribute] attribute is used to specify the level at which a service operation can accept a transaction header. This attribute has a single property and is the attribute used to annotate a service operation method.

Allowed:Transaction may be flowed.

Mandatory:Transaction must be flowed.

NotAllowed: Transaction cannot be flowed.

\

```
 [TransactionFlow(TransactionFlowOption.NotAllowed)]  public int InsertEmployee(Employee emp)  {              }
```

---

Original Source: https://www.mindstick.com/blog/10844/transaction-in-wcf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
