Azure functions Azure函数无法处理二进制Azure Servicebus消息

Azure functions Azure函数无法处理二进制Azure Servicebus消息,azure-functions,azureservicebus,azure-servicebus-queues,azure-function-app,Azure Functions,Azureservicebus,Azure Servicebus Queues,Azure Function App,或者如何让Azure函数处理二进制Azure Servicebus消息。 以下是我的Azure函数方法: public static async Task RunAsync([ServiceBusTrigger("firstqueue", Connection = "AzureServicebusConnection")] Message myQueueItem, ILogger log) { var deSerializedMessage = B

或者如何让Azure函数处理二进制Azure Servicebus消息。 以下是我的Azure函数方法:

public static async Task RunAsync([ServiceBusTrigger("firstqueue", Connection = "AzureServicebusConnection")] Message myQueueItem, ILogger log)
{
    var deSerializedMessage = BinarySerializer.Deserialize(myQueueItem.Body);
    Console.WriteLine($"Received message: SequenceNumber:{myQueueItem} Body:{deSerializedMessage.GetType().FullName}");
}
如果我用JSON序列化对象,然后将它们转换为字节数组,那么Azure函数可以处理它们

string messageBody = JsonConvert.SerializeObject(command);
return Encoding.UTF8.GetBytes(messageBody);
但如果我使用二进制序列化程序直接创建字节数组,Azure函数将无法处理它

using (var memoryStream = new MemoryStream())
{
    var formatter = new BinaryFormatter();
    formatter.Serialize(memoryStream, command);
    return memoryStream.ToArray();
}
我收到以下错误消息

执行函数时发生异常:CommandReceiver。Microsoft.Azure.WebJobs.Host:异常绑定参数“myQueueItem”。Microsoft.Azure.WebJobs.ServiceBus:ContentType为“null”的消息未能反序列化为字符串,消息为:“反序列化System.string类型的对象时出错。”。输入源的格式不正确。“。System.Private.DataContractSerialization:反序列化System.String类型的对象时出错。输入源的格式不正确。System.Private.DataContractSerialization:输入源的格式不正确

如果我使用控制台应用程序读取队列,但我想使用无服务器,那么这个二进制序列化程序可以工作


似乎我需要在发送消息时设置消息的正确内容类型,因此它不会尝试将其转换为字符串,但我找不到该设置可能是什么。或者如果这是正确的解决方案。

Azure函数假定默认内容类型为json afair。那么如何更改它?