繁体   English   中英

在MSMQ集成绑定中处理NormalizePoisonException

[英]Handle NormalizePoisonException in MSMQ Integration Binding

晚上好,

我有一个MSMQ队列,它使用msmqIntegrationBinding将消息推送到WCF服务。 receiveErrorHandling属性设置为默认值“Fault”。 偶尔,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)

消息永远不会到达服务中的方法:

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

该服务具有以下属性:

[ServiceKnownType(typeof(MyMessage))]

绑定中设置了一个死信队列:

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

WCF服务不处理该消息,并将其直接转储到日记帐队列中。 它不会留在Messaging队列中或移动到死信队列。 我试图实现一个IErrorHandler详见这里 ,但它没有达到它。

以传统方式从MSMQ收到消息时...

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

如果我按上面设置格式化程序,它可以工作。 但是,尽管在绑定中设置了serializationFormat =“Xml”,它仍然无法反序列化。

我肯定错过了一些东西。 我到处搜索了。 任何帮助是极大的赞赏。

谢谢。

经过一番激烈的谷歌搜索,我遇到了两个问题:

1)如果您希望MSMQ中的事务起作用,请确保设置队列的任何人在创建队列时将其作为事务队列。 (叹..) 创建MSMQ队列 队列proeprties

2)在IErrorHandler示例中 ,我没有集中精力进行复制和粘贴(更少咖啡,更多睡眠)并将ApplyDispatchBehavior逻辑错误地置于Validate中,其中尚未存在ChannelDispatchers(Extra sigh ...)。

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

什么是kerfluffle!

暂无
暂无

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

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