Disable DTC in WCF (MSMQ) service
I am using an MSMQ endpoint. I have set the following attributes on my service.
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void MyMethod(MyParam param) { ... }
On the interface I have
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, ReleaseServiceInstanceOnTransactionComplete = true)]
I开发者_开发知识库 have a method that makes an update to a sql server database and MSDTC is always used and the transaction is promoted.
How do I suppress this. How do I make a connection to sql server that is in a completely SEPARATE transaction to the MSMQ transaction. I want a sql transaction only, not a DTC transaction. Is there any way to ensure that the sql transaction is not included in the scope of the MSMQ transaction.
I am hoping I can do this without removing transactioning completely on MSMQ which is what I am considering.
Regards
Craig
You are complaining about core meaning of transactional MSMQ. Transactional MSMQ uses transactional reading and writing to the queue. So your message is read in the transaction and if its reading / processing fails reading is rolled back and message is not deleted from the queue. By marking your operation with TransactionScopeRequired
you are telling WCF that your operation is part of message's transactional processing. If your database operation fails it will fail MSMQ reading as well and your message is not lost. If you open database connection in your operation transaction will be promoted to DTC because you have two transactional resources in single transaction.
So if you don't want this mechanism don't use transactional queue but think about it carefully. The reason for turning off transactional queue should be that you don't need it not that you don't want distributed transactions.
精彩评论