azure - 使用 IoT DPS 通过 CreateOrUpdateIndividualEnrollmentAsync 更新设备时出错
问题描述
使用以下代码更新已注册 IoT DPS 的现有设备时发生以下错误:
执行'MyFunction'(失败,Id = xxx)System.Private.CoreLib:执行函数时出现异常:MyFunction。Microsoft.Azure.Devices.Provisioning.Service:冲突:
{"errorCode":409201,"trackingId":"xxx","message":"注册已经存在。","timestampUtc":"2019-08-07T16:27:23.3403783Z"}。
Microsoft.Azure.Devices.Provisioning.Service errorCode 409201 "Enrollment already exists."
private static async Task UpdateIndividualEnrollmentSymmetricKeyAsync()
{
var regId = GetRegistrationId("1", APP_NAME);
var symmKey = GenerateSymmetricalKey(regId, _PROVISIONING_SHARED_KEY);
Attestation attestation = new SymmetricKeyAttestation(symmKey, symmKey);
var enrollment = new IndividualEnrollment(regId, attestation);
//There are other properties, ProvisioningStatus below is only updated.
enrollment.ProvisioningStatus = ProvisioningStatus.Enabled;
//error occurred
IndividualEnrollment enrollmentResult = await _provisioningServiceClient.CreateOrUpdateIndividualEnrollmentAsync(enrollment);
}
解决方案
查看此示例,了解如何更新现有的个人注册:
您应该在更新之前检索现有的个人注册,然后调用CreateOrUpdateIndividualEnrollmentAsync
推荐阅读
- regex - 根据初始字符串搜索返回一个值
- python - 线性回归图没有给我有意义的可视化
- javascript - 对对象数组进行排序不会在 javascript 中按日期正确排序所有项目
- python - 从 Python 字典将数据插入 InfluxDB
- python - 为什么以及如何在 SRGAN 中创建神经网络 [-1,1] 的输出图像范围?
- intellij-idea - AspectJ Java maven ajc:目标 JDK 应包含在“1.1”和“1.4”之间:8
- javassist - 使用javassist动态生成类做模型映射,出现java.lang.VerifyError
- java - 缺少 HCL Domino 11.0.1 JAR 文件。JARS 在 IBM Domino 9.0.1FP9 中可用
- java - 无法在“finally”子句中关闭()流,未初始化的变量/未处理的 IOException [Java IO]
- python - 有没有办法让 python 程序在使用键盘命令执行的任何时候停止?