簡體   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