Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF msmq transactioned and unit of work

I built a MSMQ WCF service that is transactional. I used the following attribute on my operation:

[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]

I am using Nhibernate in service . Using Nhibernate I give a commit on my session. If I disable the Nhibernate commit the message is correctly processed and removed from the queues. With this commit, Nhibernate transaction goes correctly but my message goes into the retry queue.

Here is the exception that I get into Nhibernate service trace.

Description Handling an exception. Exception details: System.Transactions.TransactionAbortedException: The transaction has aborted. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Transaction'.
   at System.Transactions.Transaction.DependentClone(DependentCloneOption cloneOption)
   at System.Transactions.TransactionScope.SetCurrent(Transaction newCurrent)
   at System.Transactions.TransactionScope.PushScope()
   at System.Transactions.TransactionScope.Initialize(Transaction transactionToUse, TimeSpan scopeTimeout, Boolean interopModeSpecified)
   at System.Transactions.TransactionScope..ctor(Transaction transactionToUse, TransactionScopeAsyncFlowOption asyncFlowOption)
   at System.Transactions.TransactionScope..ctor(Transaction transactionToUse)
   at NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
   --- End of inner exception stack trace ---
   at System.Transactions.TransactionStatePromotedAborted.PromotedTransactionOutcome(InternalTransaction tx)
   at System.Transactions.TransactionStatePromotedEnded.EndCommit(InternalTransaction tx)
   at System.Transactions.CommittableTransaction.Commit()
   at System.ServiceModel.Dispatcher.TransactionInstanceContextFacet.Complete(Transaction transaction, Exception error)

It seems that the nhibernate commit destroys the transaction on WCF. I cannot find the way to fix this.

Any help may be appreciated

like image 976
Patrick Avatar asked May 01 '14 19:05

Patrick


1 Answers

I'm not too familiar with these systems, but the simplest answer is usually the right one, so I'll give it a shot - at a guess, I would say that whatever service you're calling the items to is stopping the process that removes the items before it has a chance to remove them, so I would add some sort of function call into the service you're calling the items to so it is forced to remove the item from the list before it can finish the transaction.

Of course, I'm not familiar with this topic, so don't take my word for it - that's just generally what I would do for a similar problem within the bounds of my programming knowledge.

like image 110
Dean Kuyser Avatar answered Sep 24 '22 15:09

Dean Kuyser