简体   繁体   English

在MSMQ集成绑定中处理NormalizePoisonException

[英]Handle NormalizePoisonException in MSMQ Integration Binding

Good evening, 晚上好,

I have an MSMQ queue that is pushing messages to a WCF service using msmqIntegrationBinding. 我有一个MSMQ队列,它使用msmqIntegrationBinding将消息推送到WCF服务。 The receiveErrorHandling property is set to the default of "Fault". receiveErrorHandling属性设置为默认值“Fault”。 Occasionally, MSMQ has a hissy fit trying to deserialise a message: 偶尔,MSMQ试图对消息进行反序列化:

System.ServiceModel.ProtocolException: An error was encountered while deserializing the message. The message cannot be received.
System.Runtime.Serialization.SerializationException: An error occurred while deserializing an MSMQ message's XML body. The message cannot be received. Ensure that the service contract is decorated with appropriate [ServiceKnownType] attributes or the TargetSerializationTypes property is set on the MsmqIntegrationBindingElement.
at System.ServiceModel.Channels.MsmqDecodeHelper.XmlDeserializeForIntegration(MsmqIntegrationChannelListener listener, Stream stream, Int64 lookupId)
at System.ServiceModel.Channels.MsmqDecodeHelper.DeserializeForIntegration(MsmqIntegrationChannelListener listener, Stream bodyStream, MsmqIntegrationMessageProperty property, Int64 lookupId)

The message never reaches the method in the service: 消息永远不会到达服务中的方法:

[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)] public void ProcessMessage(MsmqMessage<MyMessage> msg) {...

The service has this attribute: 该服务具有以下属性:

[ServiceKnownType(typeof(MyMessage))]

There is a dead letter queue set in the binding: 绑定中设置了一个死信队列:

<msmqIntegrationBinding>
<binding name="MyBinding" serializationFormat="Xml" exactlyOnce="false" deadLetterQueue="Custom" customDeadLetterQueue="msmq.formatname:DIRECT=OS:.\private$\services/deadLetterQueue" useMsmqTracing="true" receiveErrorHandling="Fault">

The message is not processed by the WCF service and is dumped straight into the Journal queue. WCF服务不处理该消息,并将其直接转储到日记帐队列中。 It is not left in the Messaging queue or moved to the dead letter queue. 它不会留在Messaging队列中或移动到死信队列。 I have tried implementing an IErrorHandler as detailed here but it doesn't reach it. 我试图实现一个IErrorHandler详见这里 ,但它没有达到它。

When receiving a message from MSMQ in the traditional way... 以传统方式从MSMQ收到消息时...

MessageQueue msMq = new MessageQueue(_queueName);
msMq.Formatter = new XmlMessageFormatter(new Type[] { typeof(MyMessage) });
Message m = msMq.Receive();

It works if I set the formatter as above. 如果我按上面设置格式化程序,它可以工作。 But when despite serializationFormat="Xml" being set in the binding, it still fails to deserialise. 但是,尽管在绑定中设置了serializationFormat =“Xml”,它仍然无法反序列化。

I've missed something for sure. 我肯定错过了一些东西。 I've Googled everywhere. 我到处搜索了。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

Thanks. 谢谢。

After some intense Googling I came across two issues: 经过一番激烈的谷歌搜索,我遇到了两个问题:

1) If you want transactions in MSMQ to work, make sure that whoever setup the queue made it a transactional queue when they created it. 1)如果您希望MSMQ中的事务起作用,请确保设置队列的任何人在创建队列时将其作为事务队列。 (Sigh..) (叹..) 创建MSMQ队列 队列proeprties

2) In the IErrorHandler example , I wasn't concentrating with my copying and pasting (Less coffee, more sleep) and put the ApplyDispatchBehavior logic into Validate by mistake, where no ChannelDispatchers exist yet (Extra sigh...). 2)在IErrorHandler示例中 ,我没有集中精力进行复制和粘贴(更少咖啡,更多睡眠)并将ApplyDispatchBehavior逻辑错误地置于Validate中,其中尚未存在ChannelDispatchers(Extra sigh ...)。

foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
{
    ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
    channelDispatcher.ErrorHandlers.Add(errorHandler);
}

What a kerfluffle! 什么是kerfluffle!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM