【问题标题】:The transaction aborted交易中止
【发布时间】:2012-09-18 00:54:06
【问题描述】:

我正在创建一个从 MSMQ 获取消息的 C# 和 WCF 服务。

这是使用事务性 MSMQ。在业务逻辑中,有一个条件,然后该条件将一条新消息放在不同的事务队列中,但是我似乎总是抛出异常并且不知道从这里去哪里

“System.Transactions.TransactionAbortedException:事务已中止。\r\n 在 System.Transactions.TransactionStatePromotedAborted.CreateAbortingClone(InternalTransaction tx)\r\n 在 System.Transactions.DependentTransaction..ctor(IsolationLevel isoLevel, InternalTransaction internalTransaction , 布尔阻塞)\r\n 在 System.Transactions.Transaction.DependentClone(DependentCloneOption cloneOption)\r\n 在 System.Transactions.TransactionScope.SetCurrent(Transaction newCurrent)\r\n 在 System.Transactions.TransactionScope.PushScope() \r\n 在 E:\Msmq 中的 System.Transactions.TransactionScope..ctor(TransactionScopeOption scopeOption)\r\n 在 TMC.Services.Implementation.InboundMessageHandler.Msmq.MsmqDispatcher.Dispatch(String queueFormatAndLocation, Object itemToPlaceOnQueue, Boolean traceMessage) \MsmqDispatcher.cs:第 39 行\r\n 在 TMC.Services.Implementation.InboundMessageHandler.OmhDispatcher.AckNackDispatcher.SendAckTo

E:\AckNackDispatcher.cs:第 38 行中的 Tg(SendAckToTgRequest 请求)

有什么想法吗?

将其放入队列时的代码:

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:Direct=OS:.\private$\AckMsgs”

【问题讨论】:

    标签: c# wcf msmq


    【解决方案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();
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-21
      • 2011-12-24
      相关资源
      最近更新 更多