因此,当我可以在 MSMQ 上放置消息时,旧代码库运行良好。但是,我收到的新代码库不起作用,老实说,我不知道我缺少什么。
基类:
[DataContract]
[KnownType(typeof (ReportA))]
[KnownType(typeof (AUpdate))]
[KnownType(typeof (AStatusReport))]
[KnownType(typeof (MsgHeader))]
[KnownType(typeof(BRegistationReport))]
[KnownType(typeof(BAlarmReport))]
[KnownType(typeof(AlarmData))]
[KnownType(typeof(DmpAlarmData))]
public class MyMessage {....}
然后是这里的具体类,BAarmReport(派生自MyMessage):
[DataContract]
public class BAlarmReport: MyMessage
{ ... }
然后您可以将 AlarmData 作为继承自 DmpAlarmData 的基础:
[DataContract]
public class DmpAlarmData : AlarmData
{ .. }
我将它放在 MSMQ 上的方式与以前相同,在我获得新的代码库之前一直有效:
var queue = new MessageQueue(@"FormatName:Direct=OS:" + mMSMQQueueNameAndLocation);
var msg = new Message {Body = MyMessage.CreateMessage() };
using (var ts = new TransactionScope(TransactionScopeOption.Required))
{
queue.Send(msg, MessageQueueTransactionType.Automatic); // send the message
ts.Complete(); // complete the transaction
}
我错过了什么吗?