共用方式為


TwinsClient.ReplaceAsync Method

Definition

Overloads

ReplaceAsync(String, ClientTwin, Boolean, CancellationToken)

Updates the mutable fields of a device's twin.

ReplaceAsync(String, String, ClientTwin, Boolean, CancellationToken)

Updates the mutable fields of a module's twin.

ReplaceAsync(String, ClientTwin, Boolean, CancellationToken)

Updates the mutable fields of a device's twin.

public virtual System.Threading.Tasks.Task<Microsoft.Azure.Devices.ClientTwin> ReplaceAsync (string deviceId, Microsoft.Azure.Devices.ClientTwin newTwin, bool onlyIfUnchanged = false, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceAsync : string * Microsoft.Azure.Devices.ClientTwin * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.ClientTwin>
override this.ReplaceAsync : string * Microsoft.Azure.Devices.ClientTwin * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.ClientTwin>
Public Overridable Function ReplaceAsync (deviceId As String, newTwin As ClientTwin, Optional onlyIfUnchanged As Boolean = false, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ClientTwin)

Parameters

deviceId
String

The device Id.

newTwin
ClientTwin

New twin object to replace with.

onlyIfUnchanged
Boolean

If false, this operation will be performed even if the provided device identity has an out of date ETag. If true, the operation will throw a IotHubServiceException with PreconditionFailed if the provided device identity has an out of date ETag. An up-to-date ETag can be retrieved using GetAsync(String, String, CancellationToken).

cancellationToken
CancellationToken

Task cancellation token.

Returns

updated twins.

Exceptions

When the provided deviceId or newTwin is null.

When the provided deviceId is empty or white space.

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 cancellationToken has requested cancellation.

Applies to

ReplaceAsync(String, String, ClientTwin, Boolean, CancellationToken)

Updates the mutable fields of a module's twin.

public virtual System.Threading.Tasks.Task<Microsoft.Azure.Devices.ClientTwin> ReplaceAsync (string deviceId, string moduleId, Microsoft.Azure.Devices.ClientTwin newTwin, bool onlyIfUnchanged = false, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceAsync : string * string * Microsoft.Azure.Devices.ClientTwin * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.ClientTwin>
override this.ReplaceAsync : string * string * Microsoft.Azure.Devices.ClientTwin * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Devices.ClientTwin>
Public Overridable Function ReplaceAsync (deviceId As String, moduleId As String, newTwin As ClientTwin, Optional onlyIfUnchanged As Boolean = false, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ClientTwin)

Parameters

deviceId
String

The device Id.

moduleId
String

The module Id.

newTwin
ClientTwin

New Twin object to replace with.

onlyIfUnchanged
Boolean

If false, this operation will be performed even if the provided device identity has an out of date ETag. If true, the operation will throw a IotHubServiceException with PreconditionFailed if the provided device/module identity has an out of date ETag. An up-to-date ETag can be retrieved using GetAsync(String, String, CancellationToken).

cancellationToken
CancellationToken

Task cancellation token.

Returns

Updated device twin.

Exceptions

When the provided deviceId, moduleId, or newTwin is null.

When the provided deviceId or moduleId is empty or white space.

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 cancellationToken has requested cancellation.

Applies to