WCF msmq transactioned and unit of work
Asked Answered
F

1

24

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

Felly answered 1/5, 2014 at 19:53 Comment(10)
Are you calling NH sync or async (TPL?)?Ustulation
Within the WCF service it is sync. (WCF call, call to backend class -> call to repository.) Everything in the backend class is in a complete NH transaction.Felly
Did you try this answer: #4930675 ?Prognathous
we need more code of yours because transaction object is already disposed before its get commited."Cannot access a disposed object. Object name: 'Transaction'."Archean
Why do you need to call commit explicitly? NHibernate will use any ambient available transaction but the scope of the transaction is the one of the server, that said, I don't think you should be calling commit.Rioux
have you solved this problem?Cowberry
No. And in the long run we went with entity frame and easynetq.. The latter is so much nicer for queue handlingFelly
it seems to me that the two concepts are mutually exclusive. On one hand you're using MSMQ ("please process this message at some point in the future") with a WCF call that is inherently synchronous (i.e. "do this, do it now and get back to me")Guardian
Have you got this working? I have some suggestions but I prefer not to invest time into it of the question isn't important anymore (or if OP went out of business, so to speak).Huh
We stopped the route of Nhibernate. But due to the upvotes maybe other people would be helped with an answer.Felly
S
1

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.

Sculpture answered 21/11, 2015 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.