다음을 통해 공유


DevicesClient.CreateWithTwinAsync Method

Definition

Create a device identity in your IoT hub's registry with an initial twin state.

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

Parameters

device
Device

The device identity to register.

twin
ClientTwin

The initial twin state for the device.

cancellationToken
CancellationToken

The token which allows the operation to be canceled.

Returns

The result of the bulk operation.

Exceptions

When the provided device or twin 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.

Remarks

This API uses the same underlying service API as the bulk create/set/delete APIs defined in this client such as CreateAsync(IEnumerable<Device>, CancellationToken).

Applies to