Megosztás a következőn keresztül:


ProvisioningServiceClient.CreateOrUpdateIndividualEnrollmentAsync Method

Definition

Overloads

CreateOrUpdateIndividualEnrollmentAsync(IndividualEnrollment)

Create or update a individual Device Enrollment record.

CreateOrUpdateIndividualEnrollmentAsync(IndividualEnrollment, CancellationToken)

Creates or updates an individual enrollment.

CreateOrUpdateIndividualEnrollmentAsync(IndividualEnrollment)

Create or update a individual Device Enrollment record.

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)

Parameters

individualEnrollment
IndividualEnrollment

the IndividualEnrollment object that describes the individualEnrollment that will be created of updated. It cannot be null.

Returns

An IndividualEnrollment object with the result of the create or update requested.

Exceptions

if the provided parameter is not correct.

if the SDK failed to send the request to the Device Provisioning Service.

if the Device Provisioning Service was not able to create or update the individualEnrollment.

Examples

The follow code will create a new individualEnrollment that will provisioning the registrationid-1 using TPM attestation. // IndividualEnrollment information. 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)) { // ************************************ Create the individualEnrollment **************************************** Console.WriteLine("\nCreate a new individualEnrollment..."); Attestation attestation = new TpmAttestation(TPM_ENDORSEMENT_KEY); IndividualEnrollment individualEnrollment = new IndividualEnrollment( REGISTRATION_ID, attestation); individualEnrollment.ProvisioningStatus = ProvisioningStatus.Disabled; IndividualEnrollment individualEnrollmentResult = await provisioningServiceClient.CreateOrUpdateIndividualEnrollmentAsync(individualEnrollment).ConfigureAwait(false); Console.WriteLine("\nIndividualEnrollment created with success..."); } }

The follow code will update the provisioningStatus of the previous individualEnrollment from disabled to enabled. // IndividualEnrollment information. 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)) { // ************************* Get the content of the previous individualEnrollment ****************************** Console.WriteLine("\nGet the content of the previous individualEnrollment..."); Attestation attestation = new 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("\nIndividualEnrollment updated with success..."); } }

Remarks

This API creates a new individualEnrollment or update a existed one. All enrollments in the Device Provisioning Service contains a unique identifier called registrationId. If this API is called for an individualEnrollment with a registrationId that already exists, it will replace the existed individualEnrollment information by the new one. On the other hand, if the registrationId does not exit, this API will create a new individualEnrollment.

If the registrationId already exists, this method will update existed enrollments. Note that update the individualEnrollment will not change the status of the device that was already registered using the old individualEnrollment.

To use the Device Provisioning Service API, you must include the follow package on your application. // Include the following using to use the Device Provisioning Service APIs. using Microsoft.Azure.Devices.Provisioning.Service;

Applies to

CreateOrUpdateIndividualEnrollmentAsync(IndividualEnrollment, CancellationToken)

Creates or updates an individual enrollment.

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)

Parameters

individualEnrollment
IndividualEnrollment

The individual enrollment object.

cancellationToken
CancellationToken

The cancellation token.

Returns

Applies to