简体   繁体   English

.net核心中的Azure ServiceBus消息未在.net 4.6.1中解析

[英]Azure ServiceBus message from .net core does not parse in .net 4.6.1

I have a ServiceBus in Azure and a number of queues. 我在Azure中有一个ServiceBus,并且有许多队列。 I have one service written in .net core which sends data into the queue like so: 我有一个用.net核心编写的服务,该服务将数据发送到队列中,如下所示:

queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
string example = "Hello World!";
var message = new Message(Encoding.UTF8.GetBytes(example));
await queueClient.SendAsync(message);

Other service, written in .net framework 4.6.1 is listening on that same queue like so: .net Framework 4.6.1编写的其他服务正在侦听同一队列,如下所示:

queueClient.OnMessage(ProcessQMessage);
private void ProcessQMessage (BrokeredMessage receivedMessage) {
    var tmpBytes = receivedMessage.GetBody<byte[]>();
    ...
}

For some reason i get an exception from receivedMessage.GetBody(). 由于某种原因,我从receiveMessage.GetBody()获得了异常。 I get the same exception trying to parse it to string and object as well: 我也尝试将其解析为字符串对象时遇到相同的异常:

There was an error deserializing the object of type System.Byte[]. 反序列化类型为System.Byte []的对象时出错。 The input source is not correctly formatted. 输入源的格式不正确。

I understand that the problem comes from the fact that core and framework work a little differently. 我知道问题出在核心和框架工作略有不同这一事实。 Didn't expect this to be a problem though. 没想到这是一个问题。

在此处输入图片说明

If the systems are running with old client, you will be likely stuck with XmlObjectSerializer (data contract serializer) like our .netfull client. 如果系统使用旧客户端运行,则您可能会像我们的.netfull客户端一样被XmlObjectSerializer (数据协定序列化程序)所困扰。 But things will not be broken. 但是事情不会被打破。 Sample code is like below which is exactly what happens underneath in the .netfull client. 示例代码如下所示,这正是.netfull客户端中发生的情况。

var bytes = your bytes;
var serializer = DataContractBinarySerializer<byte[]>.Instance;
using (MemoryStream stream = new MemoryStream())
{
    serializer.WriteObject(stream, bytes);
    var msg = new Message(stream.ToArray());
    var client = new Microsoft.Azure.ServiceBus.QueueClient(ConnectionString, Queue);
    await client.SendAsync(msg);
    await client.CloseAsync();
}

For more details, you could refer to this article and this issue . 有关更多详细信息,您可以参考本文本期

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Windows.Azure.ServiceBus (5.2.0) 的 ServiceBus 消息处理程序无法使用 DataContractSerializer 反序列化正文 stream。 - ServiceBus message handler using Windows.Azure.ServiceBus (5.2.0) fails to deserialise body stream using DataContractSerializer NET 4.6.1 在Azure ServiceBus上将消息从.NET Core发送方发送到.NET 4.6处理程序 - Send a message on Azure ServiceBus from .NET Core sender to a .NET 4.6 handler .Net Core 3.1.2 中的 GetFullPath 行为与 .Net 4.6.1 不同 - GetFullPath behavior in .Net Core 3.1.2 differs from .Net 4.6.1 在 .NET 4.6.1 上使用 SignalR Core - Using SignalR Core on .NET 4.6.1 Azure 不显示托管 .net 核心 API 的自定义错误消息 - Azure does not display custom error message for hosted .net core API Microsoft.Azure.ServiceBus.Message 不能用作 Azure Function 上的返回类型 Z303160EF9EDB9072D - Microsoft.Azure.ServiceBus.Message cannot be used as Azure Function return type on .NET 6.0? 对于.Net Core 2.1项目,为什么Nuget恢复.Net 4.6.1包? - For a .Net Core 2.1 project, Why does Nuget restores .Net 4.6.1 packages? 为什么.NET Core 2.0的性能比.NET Framework 4.6.1差 - Why does .NET Core 2.0 perform worse than .NET Framework 4.6.1 将数据和文件从 MVC 控制器(NET Framework 4.6.1)发送到 WebAPI 控制器(NET Core 3.0) - Send data and file from MVC Controller (NET Framework 4.6.1) to WebAPI Controller (NET Core 3.0) 错误定位.net核心RC2和.net4.6.1 - Error targeting .net core RC2 and .net4.6.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM