Message.GetBody();序列化循环
我在序列化来自 Windows Azure ServiceBus 的消息时遇到问题。
当我调用“message.GetBody();”时方法它最终会进入某种循环,这使得我的azure模拟器分配机器上的所有可用内存。
我的代码:
Microsoft.ServiceBus.Messaging.BrokeredMessage message;
while (true)
{
// SB is an instance of a class which let me receive a BrokeredMessage through its ReceiveMessage method.
message = SB.ReceiveMessage("orders");
if (message == null)
{
break;
}
// This ends up allocating lots of memory until the debugger crashes.
Procurement.TestOrder torder = message.GetBody<Procurement.TestOrder>();
}
使用的类:
[MessageContract(IsWrapped=false)]
public class TestOrder
{
[MessageBodyMember]
public int companyId { get; set; }
}
我还尝试使用 TestOrder-Class 上的 [DataContract] 和 [DataMember] 属性。
顺便说一句,该消息是一个非常简单的 XML 文件,没有任何命名空间从 BizTalk 进入 azure 中的队列。
这可能存在一些小缺陷,但我没有看到序列化器陷入循环的任何原因。
提前致谢!
I have a problem with serializing a message from Windows Azure ServiceBus.
When i Call the "message.GetBody();" method it ends up in some kind of loop which makes my azure-emulator allocate all memory available on the machine.
My code:
Microsoft.ServiceBus.Messaging.BrokeredMessage message;
while (true)
{
// SB is an instance of a class which let me receive a BrokeredMessage through its ReceiveMessage method.
message = SB.ReceiveMessage("orders");
if (message == null)
{
break;
}
// This ends up allocating lots of memory until the debugger crashes.
Procurement.TestOrder torder = message.GetBody<Procurement.TestOrder>();
}
The Used Class:
[MessageContract(IsWrapped=false)]
public class TestOrder
{
[MessageBodyMember]
public int companyId { get; set; }
}
I have also tried using the [DataContract] and [DataMember] attributes on the TestOrder-Class.
By the way, the message is a pretty simple XML-File without any namespaces coming from BizTalk into a queue in azure.
There might be some small flaws with this but i dont see any reason for the serializer to get stuck in a loop.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
[DataContract]
和[DataMember]
尝试反序列化时收到什么错误?如果您只是执行Stream s = message.GetBody();
s
包含什么?如果字符串的有效负载是文本/XML,而不是二进制序列化 XML,您可能需要传入 DataContractSerializer,如下所示:
What error do you receive when using
[DataContract]
and[DataMember]
to attempt to deserialize? If you just doStream s = message.GetBody<Stream>();
what doess
contain?If the payload of the string is text/XML as opposed to binary serialized XML you'll probably need to pass in a DataContractSerializer like this:
要进行快速测试,请尝试在 message.GetBody 之后添加 Thread.Sleep(10)。我在本地 Azure 模拟器上遇到了类似的问题,这个简单的技巧解决了它。
To make a quick test try to add a Thread.Sleep(10) after the message.GetBody. I had a similar problem with the local Azure emulator, and this simple trick solved it.