DeviceClient Class

Definition

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

public class DeviceClient : IAsyncDisposable, IDisposable
public class DeviceClient : IDisposable
public sealed class DeviceClient : IDisposable
type DeviceClient = class
    interface IDisposable
    interface IAsyncDisposable
type DeviceClient = class
    interface IDisposable
Public Class DeviceClient
Implements IAsyncDisposable, IDisposable
Public Class DeviceClient
Implements 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

AcceptDeviceStreamRequestAsync(DeviceStreamRequest)
AcceptDeviceStreamRequestAsync(DeviceStreamRequest, CancellationToken)
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.

Dispose(Boolean)

Releases the unmanaged resources used by the DeviceClient and allows for any derived class to override and provide custom implementation.

DisposeAsync()

Disposes the client in an async way. See IAsyncDisposable for more information.

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.

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.

RejectDeviceStreamRequestAsync(DeviceStreamRequest)
RejectDeviceStreamRequestAsync(DeviceStreamRequest, CancellationToken)
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 IoT hub. Use AMQP or HTTPs for a true batch operation. MQTT will just send the messages one after the other.

SendEventBatchAsync(IEnumerable<Message>, CancellationToken)

Sends a batch of events to IoT hub. Use AMQP or HTTPs for a true batch operation. MQTT will just send the messages one after the other.

SetConnectionStatusChangesHandler(ConnectionStatusChangesHandler)

Sets 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.

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. Set callback value to null to clear.

SetDesiredPropertyUpdateCallbackAsync(DesiredPropertyUpdateCallback, Object, CancellationToken)

Set a callback that will be called whenever the client receives a state update (desired or reported) from the service. Set callback value to null to clear.

SetMethodDefaultHandlerAsync(MethodCallback, Object)

Sets 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. A method handler can be unset by passing a null MethodCallback.

SetMethodDefaultHandlerAsync(MethodCallback, Object, CancellationToken)

Sets 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. A method handler can be unset by passing a null MethodCallback.

SetMethodHandler(String, MethodCallback, Object)
Obsolete.

Sets 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.

SetMethodHandlerAsync(String, MethodCallback, Object)

Sets 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. A method handler can be unset by passing a null MethodCallback.

SetMethodHandlerAsync(String, MethodCallback, Object, CancellationToken)

Sets 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. A method handler can be unset by passing a null MethodCallback.

SetReceiveMessageHandlerAsync(ReceiveMessageCallback, Object, CancellationToken)

Sets a new delegate for receiving a message from the device queue using the default timeout. After handling a received message, a client should call CompleteAsync(Message, CancellationToken), AbandonAsync(Message, CancellationToken), or RejectAsync(Message, CancellationToken), and then dispose the message. If a null delegate is passed, it will disable the callback triggered on receiving messages from the service.

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.

WaitForDeviceStreamRequestAsync()
WaitForDeviceStreamRequestAsync(CancellationToken)

Applies to