Message.GetBody();序列化循环

发布于 2024-12-24 03:28:32 字数 1096 浏览 6 评论 0原文

我在序列化来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年里的时光 2024-12-31 03:28:32

使用 [DataContract][DataMember] 尝试反序列化时收到什么错误?如果您只是执行 Stream s = message.GetBody(); s 包含什么?

如果字符串的有效负载是文本/XML,而不是二进制序列化 XML,您可能需要传入 DataContractSerializer,如下所示:

torder = message.GetBody<TestOrder>(new DataContractSerializer(typeof(TestOrder)));

What error do you receive when using [DataContract] and [DataMember] to attempt to deserialize? If you just do Stream s = message.GetBody<Stream>(); what does s 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:

torder = message.GetBody<TestOrder>(new DataContractSerializer(typeof(TestOrder)));
只有一腔孤勇 2024-12-31 03:28:32

要进行快速测试,请尝试在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文