none
Azure service bus - Read messages sent by .NET Core 2 with BrokeredMessage.GetBody RRS feed

  • Question

  • I am using .NET Core 2 for an application which needs to put a message on the Service bus and read by a legacy .NET 4.6 receiver. The receiver listens to messages from other legacy applications as well.

    Legacy sender:

    UserData obj = new UserData()
    {
      id = 1,
      name = "Alisha"
    };
    BrokeredMessage message = new BrokeredMessage(consentInstated);
    _client.Send(message);

    Legacy Receiver:

    var dataObj = objBrokeredMessage.GetBody<UserData>();
    businessFunc(dataObj.id, dataObj.name);

    .NET Core 2 sender:

    var ser = new DataContractSerializer(typeof(UserData));
    var ms = new MemoryStream();
    XmlDictionaryWriter binaryDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(ms);
    ser.WriteObject(binaryDictionaryWriter, obj);
    binaryDictionaryWriter.Flush();
    var message = new Message(ms.ToArray());

    The receiver can parse the object but it loses values, and the properties are all set to null. There seems to be a problem in the way the data is serialized. The byte array formed is different from what the BrokeredMessage creates. Is there a specific encoding format that needs to be specified?


    Rahul Lohia. Software Developer. Microsoft Technologies.

    Thursday, November 23, 2017 3:54 AM

Answers

  • Hi lohiarahul,

    Thank you for posting here and sorry for late reply.

    >>The receiver can parse the object but it loses values, and the properties are all set to null.

    Please check that whether it lose the value before receiver receive the data or not. 

    >>The byte array formed is different from what the BrokeredMessage creates. Is there a specific encoding format that needs to be specified?

    When the data send, if it is serliized, after receiver received, you could deserliaze the data. Please check the data before received, is it been changed or encrypted?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by lohiarahul Friday, December 1, 2017 5:18 AM
    Wednesday, November 29, 2017 5:43 AM
    Moderator

All replies

  • Hi lohiarahul,

    Thank you for posting here and sorry for late reply.

    >>The receiver can parse the object but it loses values, and the properties are all set to null.

    Please check that whether it lose the value before receiver receive the data or not. 

    >>The byte array formed is different from what the BrokeredMessage creates. Is there a specific encoding format that needs to be specified?

    When the data send, if it is serliized, after receiver received, you could deserliaze the data. Please check the data before received, is it been changed or encrypted?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by lohiarahul Friday, December 1, 2017 5:18 AM
    Wednesday, November 29, 2017 5:43 AM
    Moderator
  • Hi Rahul,

    I suggest a simplified workaround to send and receive message, serialize your object to Json string and send it, receive Json string and deserialize it to your object.

    Best Regards,

    Charles He


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Friday, December 1, 2017 3:20 AM