交易中止

时间:2012-09-26 11:46:21

标签: c# wcf msmq

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

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

“System.Transactions.TransactionAbortedException:事务已中止。\ r \ n在System.Transactions.TransactionStateMromitedAbortingClone(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在System.Transactions.TransactionScope..ctor(TransactionScopeOption scopeOption)\ r \ n在E:\ Msmq中的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中的Tg(SendAckToTgRequest请求):第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:\私人$ \ AckMsgs”

1 个答案:

答案 0 :(得分: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();
            }