/// <summary> /// Creates a <see cref="ServiceClient"/> using Azure Active Directory credentials and the specified transport type. /// </summary> /// <param name="hostName">IoT hub host name.</param> /// <param name="credential">Azure Active Directory credentials to authenticate with IoT hub. See <see cref="TokenCredential"/></param> /// <param name="transportType">Specifies whether Amqp or Amqp_WebSocket_Only transport is used.</param> /// <param name="transportSettings">Specifies the AMQP_WS and HTTP proxy settings for service client.</param> /// <param name="options">The options that allow configuration of the service client instance during initialization.</param> /// <returns>An instance of <see cref="ServiceClient"/>.</returns> public static ServiceClient Create( string hostName, TokenCredential credential, TransportType transportType = TransportType.Amqp, ServiceClientTransportSettings transportSettings = default, ServiceClientOptions options = default) { if (string.IsNullOrEmpty(hostName)) { throw new ArgumentNullException($"{nameof(hostName)}, Parameter cannot be null or empty"); } if (credential == null) { throw new ArgumentNullException($"{nameof(credential)}, Parameter cannot be null"); } var tokenCredentialProperties = new IotHubTokenCrendentialProperties(hostName, credential); bool useWebSocketOnly = transportType == TransportType.Amqp_WebSocket_Only; return(new AmqpServiceClient( tokenCredentialProperties, useWebSocketOnly, transportSettings ?? new ServiceClientTransportSettings(), options)); }
public AmqpServiceClient( IotHubConnectionProperties connectionProperties, bool useWebSocketOnly, ServiceClientTransportSettings transportSettings, ServiceClientOptions options) { var iotHubConnection = new IotHubConnection(connectionProperties, useWebSocketOnly, transportSettings); Connection = iotHubConnection; OpenTimeout = IotHubConnection.DefaultOpenTimeout; OperationTimeout = IotHubConnection.DefaultOperationTimeout; _faultTolerantSendingLink = new FaultTolerantAmqpObject <SendingAmqpLink>(CreateSendingLinkAsync, Connection.CloseLink); _feedbackReceiver = new AmqpFeedbackReceiver(Connection); _fileNotificationReceiver = new AmqpFileNotificationReceiver(Connection); _iotHubName = connectionProperties.IotHubName; _clientOptions = options; _httpClientHelper = new HttpClientHelper( connectionProperties.HttpsEndpoint, connectionProperties, ExceptionHandlingHelper.GetDefaultErrorMapping(), s_defaultOperationTimeout, transportSettings.HttpProxy, transportSettings.ConnectionLeaseTimeoutMilliseconds); // Set the trace provider for the AMQP library. AmqpTrace.Provider = new AmqpTransportLog(); }
public IotHubConnection(IotHubConnectionString connectionString, AccessRights accessRights, bool useWebSocketOnly, ServiceClientTransportSettings transportSettings) { ConnectionString = connectionString; _accessRights = accessRights; _faultTolerantSession = new FaultTolerantAmqpObject <AmqpSession>(CreateSessionAsync, CloseConnection); #if !NET451 _refreshTokenTimer = new IOThreadTimerSlim(s => ((IotHubConnection)s).OnRefreshToken(), this, false); #else _refreshTokenTimer = new IOThreadTimer(s => ((IotHubConnection)s).OnRefreshToken(), this, false); #endif _useWebSocketOnly = useWebSocketOnly; _transportSettings = transportSettings; }
public IotHubConnection(IotHubConnectionProperties credential, bool useWebSocketOnly, ServiceClientTransportSettings transportSettings) { #if !NET451 _refreshTokenTimer = new IOThreadTimerSlim(s => ((IotHubConnection)s).OnRefreshTokenAsync(), this); #else _refreshTokenTimer = new IOThreadTimer(s => ((IotHubConnection)s).OnRefreshTokenAsync(), this, false); #endif Credential = credential; _faultTolerantSession = new FaultTolerantAmqpObject <AmqpSession>(CreateSessionAsync, CloseConnection); _useWebSocketOnly = useWebSocketOnly; _transportSettings = transportSettings; }
public AmqpServiceClient(IotHubConnectionString iotHubConnectionString, bool useWebSocketOnly, ServiceClientTransportSettings transportSettings) { var iotHubConnection = new IotHubConnection(iotHubConnectionString, AccessRights.ServiceConnect, useWebSocketOnly, transportSettings); this.iotHubConnection = iotHubConnection; this.openTimeout = IotHubConnection.DefaultOpenTimeout; this.operationTimeout = IotHubConnection.DefaultOperationTimeout; this.sendingPath = "/messages/deviceBound"; this.faultTolerantSendingLink = new FaultTolerantAmqpObject <SendingAmqpLink>(this.CreateSendingLinkAsync, this.iotHubConnection.CloseLink); this.feedbackReceiver = new AmqpFeedbackReceiver(this.iotHubConnection); this.fileNotificationReceiver = new AmqpFileNotificationReceiver(this.iotHubConnection); this.iotHubName = iotHubConnectionString.IotHubName; this.httpClientHelper = new HttpClientHelper( iotHubConnectionString.HttpsEndpoint, iotHubConnectionString, ExceptionHandlingHelper.GetDefaultErrorMapping(), DefaultOperationTimeout, client => { }, transportSettings.HttpProxy); }
/// <summary> /// Create ServiceClient from the specified connection string using specified Transport Type /// </summary> /// <param name="connectionString">Connection string for the iothub</param> /// <param name="transportType">Specifies whether Amqp or Amqp over Websocket transport is used</param> /// <param name="transportSettings">Specifies the AMQP and HTTP proxy settings for Service Client</param> /// <returns></returns> public static ServiceClient CreateFromConnectionString(string connectionString, TransportType transportType, ServiceClientTransportSettings transportSettings) { var iotHubConnectionString = IotHubConnectionString.Parse(connectionString); bool useWebSocketOnly = (transportType == TransportType.Amqp_WebSocket_Only); var serviceClient = new AmqpServiceClient(iotHubConnectionString, useWebSocketOnly, transportSettings); return(serviceClient); }
/// <summary> /// Create an instance of ServiceClient from the specified IoT Hub connection string using specified Transport Type and transport settings. /// </summary> /// <param name="connectionString">Connection string for the IoT Hub.</param> /// <param name="transportType">The <see cref="TransportType"/> used (Amqp or Amqp_WebSocket_Only).</param> /// <param name="transportSettings">Specifies the AMQP and HTTP proxy settings for Service Client.</param> /// <param name="options">The <see cref="ServiceClientOptions"/> that allow configuration of the service client instance during initialization.</param> /// <returns>An instance of ServiceClient.</returns> public static ServiceClient CreateFromConnectionString(string connectionString, TransportType transportType, ServiceClientTransportSettings transportSettings, ServiceClientOptions options = default) { if (transportSettings == null) { throw new ArgumentNullException(nameof(transportSettings)); } var iotHubConnectionString = IotHubConnectionString.Parse(connectionString); bool useWebSocketOnly = transportType == TransportType.Amqp_WebSocket_Only; var serviceClient = new AmqpServiceClient(iotHubConnectionString, useWebSocketOnly, transportSettings, options); return(serviceClient); }
public AmqpServiceClient(IotHubConnectionString iotHubConnectionString, bool useWebSocketOnly, ServiceClientTransportSettings transportSettings, ServiceClientOptions options) { var iotHubConnection = new IotHubConnection(iotHubConnectionString, AccessRights.ServiceConnect, useWebSocketOnly, transportSettings); Connection = iotHubConnection; OpenTimeout = IotHubConnection.DefaultOpenTimeout; OperationTimeout = IotHubConnection.DefaultOperationTimeout; _sendingPath = "/messages/deviceBound"; _faultTolerantSendingLink = new FaultTolerantAmqpObject <SendingAmqpLink>(CreateSendingLinkAsync, Connection.CloseLink); _feedbackReceiver = new AmqpFeedbackReceiver(Connection); _fileNotificationReceiver = new AmqpFileNotificationReceiver(Connection); _iotHubName = iotHubConnectionString.IotHubName; _clientOptions = options; _httpClientHelper = new HttpClientHelper( iotHubConnectionString.HttpsEndpoint, iotHubConnectionString, ExceptionHandlingHelper.GetDefaultErrorMapping(), s_defaultOperationTimeout, transportSettings.HttpProxy); // Set the trace provider for the AMQP library. AmqpTrace.Provider = new AmqpTransportLog(); }