Serialization Release of Nservicebus Derived Types

to set the context, I exchange messages between my nServiceBus client and the nSerivceBus server. this is the xyz.Messages namespace and class, Message: IMessage

I have more posts that are in other dlls like xyz.Messages.Domain1, xyz.Messages.Domain2, xyz.Messages.Domain3. and messages that form this basic message, Message.

I have endpoints defined as:

 at client
<UnicastBusConfig>
 <MessageEndpointMappings>
    <add Messages="xyz.Messages" Endpoint="xyzServerQueue" />
    <add Messages="xyz.Messages.Domain1" Endpoint="xyzServerQueue" />
    <add Messages="xyz.Messages.Domain2" Endpoint="xyzServerQueue" />
  </MessageEndpointMappings>
</UnicastBusConfig>

on server

<UnicastBusConfig>
 <MessageEndpointMappings>
   <add Messages="xyz.Messages" Endpoint="xyzClientQueue" />
   <add Messages="xyz.Messages.Domain1" Endpoint="xyzClientQueue" />
   <add Messages="xyz.Messages.Domain2" Endpoint="xyzClientQueue" />
 </MessageEndpointMappings>
</UnicastBusConfig>

and a bus initialized as

        IBus serviceBus = Configure.With()
            .SpringBuilder()
            .XmlSerializer()
            .MsmqTransport()
            .UnicastBus()
            .LoadMessageHandlers()
            .CreateBus()
            .Start();

Now when I try to send an instance of a message type or data types of type type, it successfully sends the message on top and on the server, I get the correct type.

eg.

Message message= new Message();
Bus.Send(message); // works fine, transfers Message type
message = new MessageDerived1();
Bus.Send(message); // works fine, transfers MessageDerived1 type
message = new MessageDerived2();
Bus.Send(message); // works fine, transfers MessageDerived2 type

, , MessageDerived1, - Message, , . , .

public class MessageDerived2 : Message
{
  public Message message;
}

MessageDerived2 messageDerived2= new MessageDerived2();
messageDerived2.message = new MessageDerived1();
message = messageDerived2;
Bus.Send(message); // incorrect behaviour, transfers MessageDerived2 correctly, but looses type of  MessageDerived2.Message (it deserializes as Message type, instead of MessageDerived1)

.

TJ

+3
2

NServiceBus XmlSerializer - . http://tech.groups.yahoo.com/group/nservicebus/message/6549

BinarySerializer , . , DataContractSerializer , XmlSerializer .

, , , NSB - , .

+3

Udi

, , . .

-, , , - , . , ? . , ( - idempotent messaging).

-, , , , . . , XML- , .

, (, ..), , .

, .

-

+3

Source: https://habr.com/ru/post/1745064/


All Articles