首页 > 解决方案 > Azure 服务总线消息触发 Azure 函数(unicode 消息)

问题描述

关于使用 Azure Service Bus 发送带有 unicode(中文字符)的消息的问题。使用此代码发送带有 unicode 字符的消息后:

        string msgBody = JsonConvert.SerializeObject(msg);
        var message = new Message(Encoding.Unicode.GetBytes(msgBody));
        await QueueClient.SendAsync(message);
        await QueueClient.CloseAsync();

其中 msg 包含中文字符。由消息触发的 Azure 函数因异常而崩溃:

System.Private.CoreLib:执行函数时出现异常:Function1。Microsoft.Azure.WebJobs.Host:异常绑定参数“myQueueItem”。Microsoft.Azure.WebJobs.ServiceBus:ContentType 为“null”的消息无法反序列化为带有以下消息的字符串:“反序列化 System.String 类型的对象时出错。输入源的格式不正确。'。System.Private.DataContractSerialization:反序列化 System.String 类型的对象时出错。输入源的格式不正确。System.Private.DataContractSerialization:输入源的格式不正确。

知道使用 unicode 消息触发 Azure 功能吗?

标签: unicodetriggersazure-functionsazureservicebus

解决方案


固定的!UTF8 似乎运行良好。


推荐阅读