晚上好,

我有一个MSMQ队列,正在使用msmqIntegrationBinding将消息推送到WCF服务。
receiveErrorHandling属性设置为默认的“故障”。
有时,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服务处理,而是直接转储到日记队列中。它不会留在消息队列中或移到死信队列中。
我尝试将IErrorHandler实现为详细的here,但没有达到。

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

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


如果我按上述方式设置格式化程序,它将起作用。但是,即使在绑定中设置了serializationFormat =“ Xml”,它仍然无法反序列化。

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

谢谢。

最佳答案

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

1)如果您希望MSMQ中的事务能够正常工作,请确保创建队列的人将其设置为事务队列。 (叹..)
c# - 在MSMQ集成绑定(bind)中处理NormalizePoisonException-LMLPHP
c# - 在MSMQ集成绑定(bind)中处理NormalizePoisonException-LMLPHP

2)在IErrorHandler example中,我不专心于复制和粘贴(少喝咖啡,多睡一会),并且错误地将ApplyDispatchBehavior逻辑放入Validate(尚不存在ChannelDispatchers的情况下)(额外感叹...)。

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


真是个牛油果!

关于c# - 在MSMQ集成绑定(bind)中处理NormalizePoisonException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49618739/

10-13 02:00