Azure ServiceBus Message Serialization/Deserialization

前端 未结 3 673
太阳男子
太阳男子 2020-12-15 10:25

I am using a .NET Core application to send an object through an Azure Service Bus Queue and have it received by a Web Job (.NET Core as well.)

My question is how to

3条回答
  •  旧巷少年郎
    2020-12-15 11:16

    Neither of these worked for me because:

    We are getting an exception when we try to parse the body of the message as JSON because the body of the message we are receiving is

    "@\u0006string\b3http://schemas.microsoft.com/2003/10/Serialization/?\u000b{ \"a\": \"1\"}"
    

    This is because "Brokered Message Initializes a new instance of the BrokeredMessage class from a given object by using DataContractSerializer with a binary XmlDictionaryWriter."

    Ref: https://www.bfcamara.com/post/84113031238/send-a-message-to-an-azure-service-bus-queue-with

    So I used this blog post instead: https://abhishekrlal.com/2012/03/30/formatting-the-content-for-service-bus-messages/

    Example 1: Using string

    When creating a BrokeredMessage with a string and the default (DataContract + Binary) serializer:

    BrokeredMessage stringDefaultMessage = new BrokeredMessage("default string");
    

    You can receive this message as:

    string s = receiveMessage.GetBody();
    

提交回复
热议问题