24
我構建了一個MSMQ WCF服務,它是事務性的。我對我的操作使用了以下屬性:WCF msmq交易和工作單元
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
我在使用Nhibernate服務。使用Nhibernate我會對我的會話進行提交。如果我禁用Nhibernate提交,則消息會被正確處理並從隊列中移除。通過此提交,Nhibernate事務正常進行,但我的消息進入重試隊列。
這裏是我進入Nhibernate服務跟蹤的例外。
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)
看來,nhibernate提交破壞了WCF上的事務。我找不到解決這個問題的方法。
任何幫助可以理解的
你在打電話給NH同步還是異步(TPL?)? –
在WCF服務中它是同步的。 (WCF調用,調用後端類 - >調用存儲庫)。後端類中的所有內容都在一個完整的NH事務中。 – Patrick
你試過這個答案:http://stackoverflow.com/questions/4930175/nhibernate-with-transactionscope-error-dtc-transaction-preprephase-failed ? – miensol