Dela via


ServiceClient Class

Definition

Contains methods that services can use to send messages to devices.

public class ServiceClient : IDisposable
type ServiceClient = class
    interface IDisposable
Public Class ServiceClient
Implements IDisposable
Inheritance
ServiceClient
Implements

Remarks

For more information, see https://github.com/Azure/azure-iot-sdk-csharp#iot-hub-service-sdk.

This client creates lifetime long instances of HttpClient that are tied to the URI of the IoT hub specified, configure any proxy settings, and connection lease timeout. For that reason, the instances are not static and an application using this client should create and save it for all use. Repeated creation may cause socket exhaustion.

Constructors

ServiceClient()

Creates an instance of ServiceClient, provided for unit testing purposes only. Use the CreateFromConnectionString method to create an instance to use the client.

Methods

CloseAsync()

Close the ServiceClient instance. This call is made over AMQP.

Create(String, AzureSasCredential, TransportType, ServiceClientTransportSettings, ServiceClientOptions)

Creates ServiceClient using a shared access signature provided and refreshed as necessary by the caller.

Create(String, TokenCredential, TransportType, ServiceClientTransportSettings, ServiceClientOptions)

Creates ServiceClient, authenticating using an identity in Azure Active Directory (AAD).

CreateFromConnectionString(String, ServiceClientOptions)

Creates ServiceClient from an IoT hub connection string.

CreateFromConnectionString(String, TransportType, ServiceClientOptions)

Create an instance of ServiceClient from the specified IoT hub connection string using specified Transport Type.

CreateFromConnectionString(String, TransportType, ServiceClientTransportSettings, ServiceClientOptions)

Create an instance of ServiceClient from the specified IoT hub connection string using specified Transport Type and transport settings.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Dispose(Boolean)

Releases unmanaged and - optionally - managed resources.

GetFeedbackReceiver()

Get the FeedbackReceiver<T> which can deliver acknowledgments for messages sent to a device/module from IoT hub. This call is made over AMQP. For more information see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-c2d#message-feedback.

GetFileNotificationReceiver()

Get the FileNotificationReceiver<T> which can deliver notifications for file upload operations. This call is made over AMQP. For more information see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-file-upload#file-upload-notifications.

GetServiceStatisticsAsync(CancellationToken)

Gets service statistics for the IoT hub. This call is made over HTTP.

InvokeDeviceMethodAsync(String, CloudToDeviceMethod, CancellationToken)

Interactively invokes a method on a device. Additional 15s is added to the timeout in cloudToDeviceMethod to account for time taken to wire a request

InvokeDeviceMethodAsync(String, String, CloudToDeviceMethod, CancellationToken)

Interactively invokes a method on a module.

OpenAsync()

Open the ServiceClient instance. This call is made over AMQP.

PurgeMessageQueueAsync(String, CancellationToken)

Removes all cloud-to-device messages from a device's queue. This call is made over HTTP.

SendAsync(String, Message, Nullable<TimeSpan>)

Send a cloud-to-device message to the specified device. This call is made over AMQP.

SendAsync(String, String, Message, Nullable<TimeSpan>)

Send a cloud-to-device message to the specified module.

Applies to