Muppen
Muppen

Reputation: 49

Message gets weird from: Service bus/BrokeredMessage

When I send a guid as message and receive it, the message become weird:

@guid3http://schemas.microsoft.com/2003/10/Serialization/�$ed92ba5c-68ed-2a4c-8d89-0a087e47ef11

Any idea why I do not only get Guid as message?

Sender:

 public void Post(Guid id) {
            var connectionString = "X";
            var queueName = "Send";

            var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
            var message = new BrokeredMessage(id);    

            client.Send(message);                  
        }

Receiver:

  public string ReadPost() {
            var connectionString = "X";
            var queueName = "Send";

            var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
            var message = client.Receive(TimeSpan.FromMinutes(1));

            var stream = message?.GetBody<Stream>();
            if (stream == null) { return null; }

            var reader = new StreamReader(stream);
            var textFromBody = reader.ReadToEnd();

            message.Complete();

            return textFromBody;
        }

Upvotes: 2

Views: 293

Answers (1)

juunas
juunas

Reputation: 58743

Try this:

message.GetBody<Guid>();

instead of getting the stream.

Service Bus queues use DataContractSerializer to serialize the message body, which is what you are seeing.

Upvotes: 2

Related Questions