Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] Proxy settings are ignored when connecting to IoT Hub over AMQP #2242

Closed
backspacer80 opened this issue Nov 23, 2021 · 4 comments
Assignees
Labels
bug Something isn't working. customer-input-needed Issue lacks enough data for a proper investigation. IoTSDK Tracks all IoT SDK issues across the board

Comments

@backspacer80
Copy link

backspacer80 commented Nov 23, 2021

Context

  • OS, version, SKU and CPU architecture used: Windows 10 Desktop x64
  • Application's .NET Target Framework : netcoreapp3.1, net6.0
  • Device: Laptop
  • SDK version used: Microsoft.Azure.Devices.Client 1.39.0

Description of the issue

An application that is located on premises of a customer connects over AMQP to IoT Hub. The customer uses a corporate proxy.
In the application I'm creating a DeviceClient instance and opening a connection to IoT Hub over AMQP.
No matter what I enter for property AmqpTransportSettings.Proxy it seems to be ignored.
Regardless if I enter the correct address of the corporate proxy or a fake address, the SDK behaves the same:
It always manages to connect to the IoT Hub. Is the Proxy property respected at all? See minimal example below.

Code sample exhibiting the issue

// dotnet 6.0
using System.Net;
using Microsoft.Azure.Devices.Client;

RunExample();

void RunExample()
{
    using (DeviceClient deviceClient = CreateDeviceClient())
    {
        try
        {
            deviceClient.OpenAsync().GetAwaiter().GetResult();
        }
        catch (Exception e)
        {
            if (e.Message.Contains("IotHub") && e.Message.Contains("not registered"))
            {
                // We expect an exception because the device ID is made up: If that's the actual error message then we're connected!
                Console.WriteLine("Connected to IoT Hub successfully!");
            }
            else
            {
                Console.WriteLine("Not connected to IoT Hub :-(");
                throw;
            }
        }
    }
}

DeviceClient CreateDeviceClient()
{
    string deviceId = "Y2N0ZXN1";
    string authToken = "Y2N0ZXN2";
    string hostName = "example.azure-devices.net";
    string proxyHost = "10.11.12.13";
    int proxyPort = 3128;
    string? proxyUser = "***";
    string proxyPassword = "***";

    return DeviceClient.Create(
        hostName,
        new DeviceAuthenticationWithRegistrySymmetricKey(deviceId, authToken),
        new ITransportSettings[]
        {
            new AmqpTransportSettings(TransportType.Amqp_Tcp_Only)
            {
                Proxy = new WebProxy(proxyHost, proxyPort)
                {
                    Credentials = new NetworkCredential(proxyUser, proxyPassword)
                }
            }
        });
}

Console log of the issue

Connected to IoT Hub successfully!

@backspacer80 backspacer80 added the bug Something isn't working. label Nov 23, 2021
@github-actions github-actions bot added the IoTSDK Tracks all IoT SDK issues across the board label Nov 23, 2021
@jamdavi
Copy link
Member

jamdavi commented Dec 2, 2021

@backspacer80 It looks like you're using Amqp_Tcp_Only. Proxy support is only for WebSocket connections. Can you try again using Amqp_WebSocket_Only and see it it honors the proxy setting.

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.client.transporttype?view=azure-dotnet

@jamdavi jamdavi self-assigned this Dec 2, 2021
@jamdavi jamdavi added the customer-input-needed Issue lacks enough data for a proper investigation. label Dec 2, 2021
@jamdavi
Copy link
Member

jamdavi commented Dec 3, 2021

@backspacer80 Please have a look at the linked PR and let me know if this documentation would have helped when writing the code. Here is what it looks like in Visual Studio.

image

@backspacer80
Copy link
Author

@backspacer80 It looks like you're using Amqp_Tcp_Only. Proxy support is only for WebSocket connections. Can you try again using Amqp_WebSocket_Only and see it it honors the proxy setting.

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.client.transporttype?view=azure-dotnet

Yes, I switched to Amqp_WebSocket_Only and it does the job! Thank you.

@backspacer80
Copy link
Author

@backspacer80 Please have a look at the linked PR and let me know if this documentation would have helped when writing the code. Here is what it looks like in Visual Studio.

image

Yes, definitely it would have helped. I'm looking forward to the PR. I consider this one here solved and will close it. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. customer-input-needed Issue lacks enough data for a proper investigation. IoTSDK Tracks all IoT SDK issues across the board
Projects
None yet
Development

No branches or pull requests

2 participants