コード例 #1
0
        /// <summary>
        /// Creates a <see cref="ServiceClient"/> using SAS token and the specified transport type.
        /// </summary>
        /// <param name="hostName">IoT hub host name.</param>
        /// <param name="credential">Credential that generates a SAS token to authenticate with IoT hub. See <see cref="AzureSasCredential"/>.</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,
            AzureSasCredential 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  sasCredentialProperties = new IotHubSasCredentialProperties(hostName, credential);
            bool useWebSocketOnly        = transportType == TransportType.Amqp_WebSocket_Only;

            return(new AmqpServiceClient(
                       sasCredentialProperties,
                       useWebSocketOnly,
                       transportSettings ?? new ServiceClientTransportSettings(),
                       options));
        }
コード例 #2
0
        /// <summary>
        /// Creates an instance of <see cref="JobClient"/>.
        /// </summary>
        /// <param name="hostName">IoT hub host name.</param>
        /// <param name="credential">Credential that generates a SAS token to authenticate with IoT hub. See <see cref="AzureSasCredential"/>.</param>
        /// <param name="transportSettings">The HTTP transport settings.</param>
        /// <returns>An instance of <see cref="JobClient"/>.</returns>
        public static JobClient Create(
            string hostName,
            AzureSasCredential credential,
            HttpTransportSettings transportSettings = default)
        {
            if (string.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException(nameof(hostName), "Parameter cannot be null or empty.");
            }

            if (credential == null)
            {
                throw new ArgumentNullException(nameof(credential));
            }

            var sasCredentialProperties = new IotHubSasCredentialProperties(hostName, credential);

            return(new HttpJobClient(sasCredentialProperties, transportSettings ?? new HttpTransportSettings()));
        }