消息变得奇怪:服务总线/ BrokeredMessage

时间:2016-12-07 14:25:21

标签: c# asp.net-mvc azure azure-servicebus-queues

当我发送guid作为消息并接收它时,消息变得奇怪:

  

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

我知道为什么我不仅要把Guid作为信息?

发信人:

 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);                  
        }

接收者:

  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;
        }

1 个答案:

答案 0 :(得分:2)

试试这个:

message.GetBody<Guid>();

而不是获取流。

Service Bus队列使用DataContractSerializer序列化邮件正文,这就是您所看到的。