DeviceClient Class

Definition

Contains methods that a device can use to send messages to and receive from the service.

public sealed class DeviceClient : IDisposable
type DeviceClient = class
    interface IDisposable
Public NotInheritable Class DeviceClient
Implements IDisposable
Inheritance
DeviceClient
Implements

Fields

DefaultOperationTimeoutInMilliseconds

Default operation timeout.

Properties

DiagnosticSamplingPercentage

Diagnostic sampling percentage value, [0-100]; 0 means no message will carry on diagnostics info

OperationTimeoutInMilliseconds

Stores the timeout used in the operation retries. Note that this value is ignored for operations where a cancellation token is provided. For example, SendEventAsync(Message) will use this timeout, but SendEventAsync(Message, CancellationToken) will not. The latter operation will only be canceled by the provided cancellation token.

ProductInfo

Stores custom product information that will be appended to the user agent string that is sent to IoT Hub.

RetryPolicy
Obsolete.

Stores the retry strategy used in the operation retries.

Methods

AbandonAsync(Message)

Puts a received message back onto the device queue

AbandonAsync(Message, CancellationToken)

Puts a received message back onto the device queue

AbandonAsync(String)

Puts a received message back onto the device queue

AbandonAsync(String, CancellationToken)

Puts a received message back onto the device queue

CloseAsync()

Close the DeviceClient instance

CloseAsync(CancellationToken)

Close the DeviceClient instance

CompleteAsync(Message)

Deletes a received message from the device queue

CompleteAsync(Message, CancellationToken)

Deletes a received message from the device queue

CompleteAsync(String)

Deletes a received message from the device queue

CompleteAsync(String, CancellationToken)

Deletes a received message from the device queue

CompleteFileUploadAsync(FileUploadCompletionNotification, CancellationToken)

Notify IoT Hub that a device's file upload has finished. See this documentation for more details

Create(String, IAuthenticationMethod)

Creates a disposable, Amqp DeviceClient from the specified parameters

Create(String, IAuthenticationMethod, ClientOptions)

Creates a disposable DeviceClient from the specified parameters, that uses AMQP transport protocol.

Create(String, IAuthenticationMethod, ITransportSettings[], ClientOptions)

Creates a disposable DeviceClient from the specified parameters

Create(String, IAuthenticationMethod, TransportType)

Creates a disposable DeviceClient from the specified parameters

Create(String, IAuthenticationMethod, TransportType, ClientOptions)

Creates a disposable DeviceClient from the specified parameters

Create(String, String, IAuthenticationMethod, ClientOptions)

Create a disposable, AMQP DeviceClient from the specified parameters

Create(String, String, IAuthenticationMethod, ITransportSettings[], ClientOptions)

Creates a disposable DeviceClient from the specified parameters

Create(String, String, IAuthenticationMethod, TransportType, ClientOptions)

Create a disposable DeviceClient from the specified parameters

CreateFromConnectionString(String)

Creates a disposable DeviceClient using Amqp transport from the specified connection string

CreateFromConnectionString(String, ClientOptions)

Creates a disposable DeviceClient using AMQP transport from the specified connection string

CreateFromConnectionString(String, ITransportSettings[], ClientOptions)

Create a disposable DeviceClient from the specified connection string using a prioritized list of transports

CreateFromConnectionString(String, String)

Creates a disposable DeviceClient using Amqp transport from the specified connection string

CreateFromConnectionString(String, String, ClientOptions)

Creates a disposable DeviceClient using AMQP transport from the specified connection string

CreateFromConnectionString(String, String, ITransportSettings[], ClientOptions)

Creates a disposable DeviceClient from the specified connection string using the prioritized list of transports

CreateFromConnectionString(String, String, TransportType)

Creates a disposable DeviceClient from the specified connection string using the specified transport type

CreateFromConnectionString(String, String, TransportType, ClientOptions)

Creates a disposable DeviceClient from the specified connection string using the specified transport type

CreateFromConnectionString(String, TransportType)

Creates a disposable DeviceClient from the specified connection string using the specified transport type

CreateFromConnectionString(String, TransportType, ClientOptions)

Creates a disposable DeviceClient from the specified connection string using the specified transport type

Dispose()

Releases the unmanaged resources used by the DeviceClient and optionally disposes of the managed resources.

GetFileUploadSasUriAsync(FileUploadSasUriRequest, CancellationToken)

Get a file upload SAS URI which the Azure Storage SDK can use to upload a file to blob for this device. See this documentation for more details

GetTwinAsync()

Retrieve the device twin properties for the current device. For the complete device twin object, use Microsoft.Azure.Devices.RegistryManager.GetTwinAsync(string deviceId).

GetTwinAsync(CancellationToken)

Retrieve the device twin properties for the current device. For the complete device twin object, use Microsoft.Azure.Devices.RegistryManager.GetTwinAsync(string deviceId).

OpenAsync()

Explicitly open the DeviceClient instance.

OpenAsync(CancellationToken)

Explicitly open the DeviceClient instance.

A cancellation token to cancel the operation.Thrown when the operation has been canceled.
ReceiveAsync()

Receive a message from the device queue using the default timeout. After handling a received message, a client should call CompleteAsync(Message), AbandonAsync(Message), or RejectAsync(Message), and then dispose the message.

ReceiveAsync(CancellationToken)

Receive a message from the device queue using the cancellation token. After handling a received message, a client should call CompleteAsync(Message, CancellationToken), AbandonAsync(Message, CancellationToken), or RejectAsync(Message, CancellationToken), and then dispose the message.

ReceiveAsync(TimeSpan)

Receive a message from the device queue using the cancellation token. After handling a received message, a client should call CompleteAsync(Message, CancellationToken), AbandonAsync(Message, CancellationToken), or RejectAsync(Message, CancellationToken), and then dispose the message.

RejectAsync(Message)

Deletes a received message from the device queue and indicates to the server that the message could not be processed.

RejectAsync(Message, CancellationToken)

Deletes a received message from the device queue and indicates to the server that the message could not be processed.

RejectAsync(String)

Deletes a received message from the device queue and indicates to the server that the message could not be processed.

RejectAsync(String, CancellationToken)

Deletes a received message from the device queue and indicates to the server that the message could not be processed.

SendEventAsync(Message)

Sends an event to a hub

SendEventAsync(Message, CancellationToken)

Sends an event to a hub

SendEventBatchAsync(IEnumerable<Message>)

Sends a batch of events to a hub. Requires AMQP or AMQP over WebSockets.

SendEventBatchAsync(IEnumerable<Message>, CancellationToken)

Sends a batch of events to device hub. Requires AMQP or AMQP over WebSockets.

SetConnectionStatusChangesHandler(ConnectionStatusChangesHandler)

Registers a new delegate for the connection status changed callback. If a delegate is already associated, it will be replaced with the new delegate. Note that this callback will never be called if the client is configured to use HTTP as that protocol is stateless

The name of the method to associate with the delegate.
SetDesiredPropertyUpdateCallback(DesiredPropertyUpdateCallback, Object)
Obsolete.

Set a callback that will be called whenever the client receives a state update (desired or reported) from the service. This has the side-effect of subscribing to the PATCH topic on the service.

SetDesiredPropertyUpdateCallbackAsync(DesiredPropertyUpdateCallback, Object)

Set a callback that will be called whenever the client receives a state update (desired or reported) from the service. This has the side-effect of subscribing to the PATCH topic on the service.

SetDesiredPropertyUpdateCallbackAsync(DesiredPropertyUpdateCallback, Object, CancellationToken)

Set a callback that will be called whenever the client receives a state update (desired or reported) from the service. This has the side-effect of subscribing to the PATCH topic on the service.

SetMethodDefaultHandlerAsync(MethodCallback, Object)

Registers a new delegate that is called for a method that doesn't have a delegate registered for its name. If a default delegate is already registered it will replace with the new delegate.

SetMethodDefaultHandlerAsync(MethodCallback, Object, CancellationToken)

Registers a new delegate that is called for a method that doesn't have a delegate registered for its name. If a default delegate is already registered it will replace with the new delegate.

SetMethodHandler(String, MethodCallback, Object)
Obsolete.

Registers a new delegate for the named method. If a delegate is already associated with the named method, it will be replaced with the new delegate.

The name of the method to associate with the delegate.The delegate to be used when a method with the given name is called by the cloud service.generic parameter to be interpreted by the client code.
SetMethodHandlerAsync(String, MethodCallback, Object)

Registers a new delegate for the named method. If a delegate is already associated with the named method, it will be replaced with the new delegate.

The name of the method to associate with the delegate.The delegate to be used when a method with the given name is called by the cloud service.generic parameter to be interpreted by the client code.
SetMethodHandlerAsync(String, MethodCallback, Object, CancellationToken)

Registers a new delegate for the named method. If a delegate is already associated with the named method, it will be replaced with the new delegate.

The name of the method to associate with the delegate.The delegate to be used when a method with the given name is called by the cloud service.generic parameter to be interpreted by the client code.A cancellation token to cancel the operation.Thrown when the operation has been canceled.
SetRetryPolicy(IRetryPolicy)

Sets the retry policy used in the operation retries. The change will take effect after any in-progress operations.

UpdateReportedPropertiesAsync(TwinCollection)

Push reported property changes up to the service.

UpdateReportedPropertiesAsync(TwinCollection, CancellationToken)

Push reported property changes up to the service.

UploadToBlobAsync(String, Stream)
Obsolete.

Uploads a stream to a block blob in a storage account associated with the IoTHub for that device. If the blob already exists, it will be overwritten.

UploadToBlobAsync(String, Stream, CancellationToken)
Obsolete.

Uploads a stream to a block blob in a storage account associated with the IoTHub for that device. If the blob already exists, it will be overwritten.

Applies to