通过CreateOrUpdateIndividualEnrollmentAsync与IoT DPS更新设备时出错

时间:2019-08-07 17:15:39

标签: azure azure-iot-hub

使用以下代码更新已注册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);

    }

1 个答案:

答案 0 :(得分:0)

对此sample进行了解,了解如何更新现有的个人注册:

您应该先获取现有的个人注册,然后再进行更新,然后调用 CreateOrUpdateIndividualEnrollmentAsync