The following is what is in this article:
- Introduction
- Transactions
- Throttling
- Attachment
- Summary
Introduction
Your good behavior makes you a better person, am I right? Yes if you are showing your good behavior towards other people then better communication will form. Such as if you apply the right behavior on various parts of your WCF system, you will be able to influence the WCF service in regard to things concurrency, session management, throttling and transactions. Behaviors can be applied at the service, operation, endpoint and contract levels.
Few behavior configurations can be done on the configuration side and a few can be at the source code side.
Service Behavior
The [Service Behavior] attribute is used to apply behavior at the service level. It allows you to control things such as:
- Concurrency
- Throttling
- Transaction
- Session Management
- Thread Behavior
The preceding can be done by setting its properties.
Service Behavior Properties
| Property | What for? |
| Address Filter Mode | Allows you to change the Message Filter. This property has three values Any, Exact and Prefix. Used by the Dispatcher to identify the correct endpoint responsible to handle incoming messages. |
| Automatic Session ShutDown | Boolean Field, stops the server from closing the session when all the incoming messages have been processed. By default it is true. By make it false you are able to control the session lifetime. |
| Concurrency Mode | This is set if the service runs on a single thread or multiple threads. |
| IgnoreExtensionDataObject | Boolean Field. False by default. If set to true then any unknown serialization data is not sent with the message. |
| IncludeExceptionDetailinFaults | Set to True if you want to get the unhandled exception sent to the client as a SOAP fault. Set to False in a production environment, set to True in a development environment |
| InstanceContextMode | Used to set the lifetime of the service instance. The allowed values are Per session, Per call and Single. |
| MaxItemsinObjectGraph | This sets to Maximum allowed items in the serialized/deserialized object graph. Sometimes you receive an exception when you serialize/deserialize the maximum number of items. Increase this property to match your case. |
| ReleaseServiceInstanceOnTransactionComplete | If set to true, the service object will be released when the active transaction is complete. |
| TransactionAutoCompleteOnSessionClose | Set to true if you want to mark the active transaction as complete when the session is closed by client without error. |
| TransactionTimeOut | Sometimes a transaction can take more time to complete. You can set a timeout after which the session is considered as aborted and the rollback process is started. |
Session management and the Concurrency are really important and are the most useful properties in Service Behavior. In my future article, you can find detailed explanations on Session Management and concurrency, but here we will concentrate only on the Transactions and Throttling.
Transactions
A transaction is a logical unit of work consisting of multiple activities that must either succeed or fail together. For example, you are trying to make an online purchase for a dress; your amount is debited from the bank, but your ordered dress was not delivered to you. So what did you get from the preceding example? Bank operations hosted in a separate service and the online purchase service (Ordering the goods) hosted as another separate service. For the preceding example, the online purchase service did not work well as expected due to the database query error, without knowing it the Bank operations were completed perfectly. For this, we really need transactions to ensure that either of the operations should succeed or fail. Before we go to the WCF transactions, let us discuss what exactly are the basics behind the transactions.
The following are the types of Transactions:
- Atomic
- Long Running
Long Running transactions are the ones that take more time to finish. For example, a client sending a request to the service but it takes more days or months to provide a response to the client. Yes of course until that period of time has completed we should not lock down the resources like SQL Server, so this case cannot be handled by Atomic Transactions.
Transaction Protocols
Lightweight Protocol: It is used when a single application inside an appdomain is working with a single RM (SQL Server or any component participating in transactions).
- Lightweight Protocol
- OleTx Protocol
- WSAT Protocol
OleTx Protocol: It allows Cross AppDomain, used for Windows-intranet scenarios. No cross-platform communication allowed, no communication through the firewall is allowed.
WSAT Protocol: Similar to OleTx, but this will go across firewalls and platforms.
I hope the preceding one is still unclear for you guys, let me try to explain it in another way. A WCF service calls into SQL Server for multiple updates to be done, that are all enlisted as a single transaction. A WCF service is called by the clients running on the same machine or various Windows machine. In this case OleTx protocol is used to maintain the transaction. In the same above situation if one of your clients is a Java client, the WSAT protocol will be used since it is a cross-platform interoperability.
WCF Transactions
Now to see here how the transactions will be done using WCF. The following is the really important procedure to configure transactions.
- Transaction Bindings
- Transaction Flow Option
- TransactionScope (Client and Server)
- Configuring Transaction Modes


Governor BaloyiPosted Apr 1, 2020, 11:10 AM
Thanks a lot. It’s helpful
Pankajkumar PatelPosted Sep 9, 2019, 1:22 AM
Nice one ...
Hadshana KamalanathanPosted Sep 4, 2018, 8:10 PM
Thanks for sharing...
SubashPosted Oct 11, 2016, 7:05 AM
Good one
Arul RPosted Jan 19, 2016, 2:43 AM
Nice article super
Ramesh KartikPosted Aug 14, 2015, 1:29 AM
Thanks
salim skPosted Aug 9, 2015, 3:22 AM
Thank you Ramesh,It is really a useful article.