你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

ProvisioningServiceClient.CreateOrUpdateIndividualEnrollmentAsync 方法

定义

重载

CreateOrUpdateIndividualEnrollmentAsync(IndividualEnrollment)

创建或更新单个设备注册记录。

CreateOrUpdateIndividualEnrollmentAsync(IndividualEnrollment, CancellationToken)

创建或更新单个注册。

CreateOrUpdateIndividualEnrollmentAsync(IndividualEnrollment)

创建或更新单个设备注册记录。

public System.Threading.Tasks.Task<Microsoft.Azure.Devices.Provisioning.Service.IndividualEnrollment> CreateOrUpdateIndividualEnrollmentAsync (Microsoft.Azure.Devices.Provisioning.Service.IndividualEnrollment individualEnrollment);
member this.CreateOrUpdateIndividualEnrollmentAsync : Microsoft.Azure.Devices.Provisioning.Service.IndividualEnrollment -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.Provisioning.Service.IndividualEnrollment>
Public Function CreateOrUpdateIndividualEnrollmentAsync (individualEnrollment As IndividualEnrollment) As Task(Of IndividualEnrollment)

参数

individualEnrollment
IndividualEnrollment

对象 IndividualEnrollment ,该对象描述将创建的更新的 individualEnrollment。 它不能为 null

返回

具有 IndividualEnrollment 请求的创建或更新结果的 对象。

例外

如果提供的参数不正确,则为 。

如果 SDK 未能将请求发送到设备预配服务,则为 。

如果设备预配服务无法创建或更新 individualEnrollment,则为 。

示例

以下代码将创建一个新的 individualEnrollment,它将使用 TPM 证明预配 registrationid-1。 IndividualEnrollment 信息。private const string PROVISIONING_CONNECTION_STRING = “HostName=ContosoProvisioning.azure-devices-provisioning.net;” + “SharedAccessKeyName=contosoprovisioningserviceowner;” + “SharedAccessKey=dGVzdFN0cmluZzE=”;private const string TPM_ENDORSEMENT_KEY = “tpm-endorsement-key”;private const string REGISTRATION_ID = “registrationid-1”;

static void Main (string[] args) { RunSample () .GetAwaiter () 。GetResult () ;}

public static async Task RunSample () { using (ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString (PROVISIONING_CONNECTION_STRING) ) { // 创建 individualEnrollment **** Console.WriteLine (“\n创建新的 individualEnrollment...”) ;证明证明 = 新的 TpmAttestation (TPM_ENDORSEMENT_KEY) ;IndividualEnrollment individualEnrollment = new IndividualEnrollment ( REGISTRATION_ID,证明) ;individualEnrollment.ProvisioningStatus = ProvisioningStatus.Disabled;IndividualEnrollment individualEnrollmentResult = await provisioningServiceClient.CreateOrUpdateIndividualEnrollmentAsync (individualEnrollment) 。ConfigureAwait (false) ;Console.WriteLine (“\n成功创建的 IndividualEnrollment...”) ;} }

以下代码会将上一个个人注册的 provisioningStatus 从 禁用 更新为 启用 IndividualEnrollment 信息。private const string PROVISIONING_CONNECTION_STRING = “HostName=ContosoProvisioning.azure-devices-provisioning.net;” + “SharedAccessKeyName=contosoprovisioningserviceowner;” + “SharedAccessKey=dGVzdFN0cmluZzE=”;private const string REGISTRATION_ID = “registrationid-1”;

static void Main (string[] args) { RunSample () .GetAwaiter () 。GetResult () ;}

public static async Task RunSample () { using (ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.CreateFromConnectionString (PROVISIONING_CONNECTION_STRING) ) { // *******************获取上一个人注册的内容 *********控制台.WriteLine (“\n获取上一个人注册的内容...”) ;证明证明 = 新的 TpmAttestation (TPM_ENDORSEMENT_KEY) ;IndividualEnrollment individualEnrollment = await deviceProvisioningServiceClient.GetIndividualEnrollmentAsync (REGISTRATION_ID) 。ConfigureAwait (false) ;individualEnrollment.ProvisioningStatus = ProvisioningStatus.Enabled;IndividualEnrollment individualEnrollmentResult = await provisioningServiceClient.CreateOrUpdateIndividualEnrollmentAsync (individualEnrollment) 。ConfigureAwait (false) ;Console.WriteLine (“\n个人注册更新成功...”) ;} }

注解

此 API 创建新的 individualEnrollment 或更新现有的个人注册。 设备预配服务中的所有注册都包含名为 registrationId 的唯一标识符。 如果为具有已存在的 registrationId 的 individualEnrollment 调用此 API,它将用新注册信息替换现有的 individualEnrollment 信息。 另一方面,如果 registrationId 未退出,此 API 将创建新的 individualEnrollment。

如果 registrationId 已存在,此方法将更新现有的注册。 请注意,更新 individualEnrollment 不会更改已使用旧 individualEnrollment 注册的设备的状态。

若要使用设备预配服务 API,必须在应用程序中包括以下包。 // Include the following using to use the Device Provisioning Service APIs. using Microsoft.Azure.Devices.Provisioning.Service;

适用于

CreateOrUpdateIndividualEnrollmentAsync(IndividualEnrollment, CancellationToken)

创建或更新单个注册。

public System.Threading.Tasks.Task<Microsoft.Azure.Devices.Provisioning.Service.IndividualEnrollment> CreateOrUpdateIndividualEnrollmentAsync (Microsoft.Azure.Devices.Provisioning.Service.IndividualEnrollment individualEnrollment, System.Threading.CancellationToken cancellationToken);
member this.CreateOrUpdateIndividualEnrollmentAsync : Microsoft.Azure.Devices.Provisioning.Service.IndividualEnrollment * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.Provisioning.Service.IndividualEnrollment>
Public Function CreateOrUpdateIndividualEnrollmentAsync (individualEnrollment As IndividualEnrollment, cancellationToken As CancellationToken) As Task(Of IndividualEnrollment)

参数

individualEnrollment
IndividualEnrollment

单个注册对象。

cancellationToken
CancellationToken

取消标记。

返回

适用于