首页 > 解决方案 > 使用 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);

    }

标签: azureazure-iot-hub

解决方案


查看此示例,了解如何更新现有的个人注册:

您应该在更新之前检索现有的个人注册,然后调用CreateOrUpdateIndividualEnrollmentAsync


推荐阅读