我有一个使用servicebus的简单网络作业:
public async Task ProcessQueueMessage([ServiceBusTrigger("asset-updates-in")] BrokeredMessage message,
ILogger log)
{
log.LogInformation("Running job");
log.LogInformation("GotMessage"+ message.ContentType);
消息是由Biztalk团队发送的,具有MIME类型“ text / xml” 看起来像这样:
<gip:GetDeviceUpdateResult xmlns:gip="http://schemas.ores.net/customer/breakdown-manager/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<gip:Event>
<gip:Id>5886</gip:Id>
<gip:Action>Upsert</gip:Action>
<gip:Timestamp>2019-09-20T13:35:40</gip:Timestamp>
</gip:Event>
<gip:Cabin>
<gip:Id>5001874</gip:Id>
<gip:BusinessId>029843</gip:BusinessId>
<gip:Name>RUE DE LANDEN TEST 2</gip:Name>
<gip:DistrictId>1590</gip:DistrictId>
</gip:Cabin>
</gip:GetDeviceUpdateResult>
我的网络工作收到消息后,我便出现此错误:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException:异常 执行函数时:UpdateFunctions.ProcessQueueMessage ---> System.InvalidOperationException:异常绑定参数 '消息'---> System.InvalidOperationException:将参数绑定到 复杂对象(例如“ BrokeredMessage”)使用Json.NET 序列化或XML对象序列化。
- 如果ContentType为'application / json',则反序列化为JSON
- 如果ContentType不是'application / json',则尝试使用Message.GetBody反序列化,这将处理XML对象之类的情况 序列化
- 如果该反序列化失败,请最后尝试进行JSON反序列化,以捕获可能是内容类型为 不正确
JSON解析器失败:解析时遇到意外字符 值:?。路径”,第0行,位置0。
因此,似乎是使用json解析器,而数据是来自atat的xml ...
如果我这样更改我的网络作业:
public async Task ProcessQueueMessage([ServiceBusTrigger("asset-updates-in")] string message,
ILogger log)
{
log.LogInformation("Running job");
log.LogInformation("GotMessage"+ message);
我明白了:
[09/20/2019 11:38:43 > da4c4f: INFO] GotMessage<?xml version="1.0" encoding="utf-8"?><gip:GetDeviceUpdateResult xmlns:gip="http://schemas.ores.net/customer/breakdown-manager/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><gip:Event><gip:Id>5889</gip:Id><gip:Action>Upsert</gip:Action><gip:Timestamp>2019-09-20T13:38:11</gip:Timestamp></gip:Event><gip:Cabin><gip:Id>5001874</gip:Id><gip:BusinessId>029843</gip:BusinessId><gip:Name>RUE DE LANDEN</gip:Name><gip:DistrictId>1590</gip:DistrictId></gip:Cabin></gip:GetDeviceUpdateResult>
[09/20/2019 11:38:43 > da4c4f: INFO] info: Function.ProcessQueueMessage[0]
我想我可以反序列化自己,但是有点恶臭……我缺少了什么?
谢谢!
答案 0 :(得分:1)
这是因为在webjob 3.x中不推荐使用override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if self.traitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle {
// Your custom implementation here that is run right after the userInterfaceStyle has changed.
}
}
类。
WebJobs SDK版本3.x正在使用新的.NET Standard服务总线客户端(带有Message类的BrokeredMessage
)。
因此您可以使用它反序列化。
Microsoft.Azure.ServiceBus