views:

18

answers:

1

Hi All
I'm using a custom message that inherits the System.Servicemodel.Channels.Message.
My custom message get IEnumerable collection which pulled from a database.
The WCF service is transactional (which is already tested).

MS-DTC is enabled.

Problem is, that when the protected override void OnWriteBodyContents(XmlDictionaryWriter writer) method is executed at the custom message, there is no transaction.
The System.Transactions.Transaction.Current is null. while executing the service the transaction flow is works fine, but when the message is written by WCF mechanism, it's seems like it's out of a transaction which cause the DB command (of pulling the data) to be executed without transaction.
Please note, that if I'm passing simple array instead of IEnumerable the DB action is executed under transaction, but I want it to be executed parallelly with the response writing.

Any ideas please, why the transaction is missing and what can be done to activate it?

many thanks!
Tamir.

+1  A: 

Transaction are generally attached to your current thread or calling context. So if you are initiating transaction on different thread and message serialization is happing on another thread then transaction won't be available on that thread. You should look at TransactionScope and DependentTransaction for supporting such scenarios.

VinayC
you're great! thanks for that.but, how could I solve this kind of issues before fx 4.0?
Tamir
Actually, DepedentTransaction exist since introduction of System.Transactions i.e. .NET 2.0
VinayC
yes, sorry, my bad. didn't noticed that.. :-)
Tamir