Condividi tramite


DevicesClient.CreateAsync Method

Definition

Overloads

CreateAsync(Device, CancellationToken)

Create a device identity in your IoT hub's registry.

CreateAsync(IEnumerable<Device>, CancellationToken)

Create up to 100 new device identities in your IoT hub's registry in bulk.

CreateAsync(Device, CancellationToken)

Create a device identity in your IoT hub's registry.

public virtual System.Threading.Tasks.Task<Microsoft.Azure.Devices.Device> CreateAsync (Microsoft.Azure.Devices.Device device, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateAsync : Microsoft.Azure.Devices.Device * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.Device>
override this.CreateAsync : Microsoft.Azure.Devices.Device * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.Device>
Public Overridable Function CreateAsync (device As Device, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Device)

Parameters

device
Device

The device identity to register.

cancellationToken
CancellationToken

The token which allows the operation to be canceled.

Returns

The registered device with the generated keys and ETags.

Exceptions

When the provided device is null.

If IoT hub responded to the request with a non-successful status code. For example, if the provided request was throttled, IotHubServiceException with ThrottlingException is thrown. For a complete list of possible error cases, see IotHubServiceErrorCode.

If the HTTP request fails due to an underlying issue such as network connectivity, DNS failure, or server certificate validation.

If the provided cancellation token has requested cancellation.

Applies to

CreateAsync(IEnumerable<Device>, CancellationToken)

Create up to 100 new device identities in your IoT hub's registry in bulk.

public virtual System.Threading.Tasks.Task<Microsoft.Azure.Devices.BulkRegistryOperationResult> CreateAsync (System.Collections.Generic.IEnumerable<Microsoft.Azure.Devices.Device> devices, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateAsync : seq<Microsoft.Azure.Devices.Device> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.BulkRegistryOperationResult>
override this.CreateAsync : seq<Microsoft.Azure.Devices.Device> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.BulkRegistryOperationResult>
Public Overridable Function CreateAsync (devices As IEnumerable(Of Device), Optional cancellationToken As CancellationToken = Nothing) As Task(Of BulkRegistryOperationResult)

Parameters

devices
IEnumerable<Device>

The device identities to create in your IoT hub's registry. May not exceed 100 devices.

cancellationToken
CancellationToken

The token which allows the operation to be canceled.

Returns

The result of the bulk operation.

Exceptions

When the provided device collection is null.

When the provided device collection is empty.

If IoT hub responded to the request with a non-successful status code. For example, if the provided request was throttled, IotHubServiceException with ThrottlingException is thrown. For a complete list of possible error cases, see IotHubServiceErrorCode.

If the HTTP request fails due to an underlying issue such as network connectivity, DNS failure, or server certificate validation.

If the provided cancellation token has requested cancellation.

Remarks

For larger scale operations, consider using ImportAsync(ImportJobProperties, CancellationToken) which allows you to import devices from an Azure Storage container.

Applies to