So the old code base was working fine when I could place a message on MSMQ. However the new codebase I received does not work and no idea what I am missing to be honest.
Base class:
[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 {....}
Then the specific class here, BAlarmReport (derives from MyMessage):
[DataContract]
public class BAlarmReport: MyMessage
{ ... }
Then you can have AlarmData as a base which is inherited from DmpAlarmData:
[DataContract]
public class DmpAlarmData : AlarmData
{ .. }
The way I am placing it on MSMQ is the same as before, which was working until I got the new codebase:
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
}
am I missing something?
Fixed. sigh
Digging through the inner exceptions led me to the problem where some of the classes did not have a parameterless constructor. But also the subclasses should be declared with the XmlInclude attribute on the base class itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.