2012-09-26 114 views
0

即時通訊創建一個C#和WCF服務,它從MSMQ中接收消息。交易異常中止

這是使用事務性MSMQ。在業務邏輯中,有一個條件和條件,然後在另一個事務隊列中放置一條新消息,但是我似乎總是會拋出異常並且不確定從這裏去哪裏

「System.Transactions.TransactionAbortedException:在System.Transactions.DependentTransaction..ctor(IsolationLevel isoLevel,InternalTransaction internalTransaction,布爾阻塞)上的System.Transactions.TransactionStatePromotedAborted.CreateAbortingClone(InternalTransaction tx)\ r \ n \ r \ n在系統上\ r \ n .Transactions.Transaction.DependentClone(DependentCloneOption cloneOption)\ r \ n在System.Transactions.TransactionScope.SetCurrent(Transaction newCurrent)\ r \ n在System.Transactions.TransactionScope.PushScope()\ r \ n在System.Transactions.TransactionScope ..(TransactionScopeOption scopeOption)\ r \ n在TMC.Services.Implementation.In boundMessageHandler.Msmq.MsmqDispatcher.Dispatch(字符串queueFormatAndLocation,對象itemToPlaceOnQueue,布爾traceMessage)在E:\ MSMQ \ MsmqDispatcher.cs:線39 \ r \ n在TMC.Services.Implementation.InboundMessageHandler.OmhDispatcher.AckNackDispatcher.SendAckTo

Tg(SendAckToTgRequest請求)在E:\ AckNackDispatcher.cs:38行「

任何想法?

當把它放在隊列中的代碼:

var queue = new MessageQueue(queueFormatAndLocation); 
      var msg = new System.Messaging.Message {Body = itemToPlaceOnQueue, Priority = MessagePriority.High, UseDeadLetterQueue = true, UseTracing = traceMessage}; 
      using (var ts = new TransactionScope(TransactionScopeOption.Required)) 
      { 
       queue.Send(msg, MessageQueueTransactionType.Automatic); // send the message 
       ts.Complete(); // complete the transaction 
      } 

在queueFormatAndLocation而言,這是正確的:

「FORMATNAME:直接= OS:。\ PRIVATE $ \ AckMsgs 「

回答

1

這有助於和似乎工作:

http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(%22SYSTEM.MESSAGING.MESSAGEQUEUETRANSACTION.%23CTOR%22);k(SOLUTIONITEMSPROJECT);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true

http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(%22SYSTEM.MESSAGING.MESSAGEQUEUE.%23CTOR%22);k(SOLUTIONITEMSPROJECT);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true

基本上使用MessageQueueTransasction和MessageQueue類。 MQT的原因是在現有事務中使用它(在我的場景中)。這似乎工作。

代碼:

using (var mqt = new MessageQueueTransaction()) 
      { 
       mqt.Begin(); 
       MessageQueue mq = new MessageQueue(queueFormatAndLocation); 
       mq.Send(itemToPlaceOnQueue, mqt); 
       mqt.Commit(); 
      }