Azure-iot-sdk-csharp: SetConnectionStatusChangesHandler not working as expected on TransportType.Http1

Created on 21 Mar 2019  ·  3Comments  ·  Source: Azure/azure-iot-sdk-csharp

  • OS, version, SKU and CPU architecture used: Windows 10 Desktop x64
  • Application's .NET Target Framework : .net framework 4.7
  • Device: Laptop
  • SDK version used: Microsoft.Azure.Devices.Client 1.19.0.0

Description of the issue:

The "SetConnectionStatusChangesHandler" only be fired when connection established at the first time and close application when TransportType is set to Http1. When i change the network, it could not be fired. :(

I also tried the other TransportType to Amqp/Amqp_Tcp_Only/Amqp_WebSocket_Only/Mqtt/Mqtt_Tcp_Only/Mqtt_WebSocket_Only with the same code. They all works well: every time i changed the network, i will show the message box OK/Retry. (also include connection established at the first time and close application)

Am i missing something? Or it doesn't support Http1?

Reference:
it seems not mention the limitation of TransportType
https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.client.deviceclient.setconnectionstatuschangeshandler

Code sample exhibiting the issue:

private async Task ReceiveC2dAsync()
{
        deviceClient = DeviceClient.Create(IoTHostName, new DeviceAuthenticationWithRegistrySymmetricKey(strDeviceId, strDeviceKey), Microsoft.Azure.Devices.Client.TransportType.Http1);
        deviceClient.SetConnectionStatusChangesHandler(ConnectionStatusChanges);
        await deviceClient.OpenAsync();

        await deviceClient.SetDesiredPropertyUpdateCallbackAsync(DesiredPropertiesUpdates, null);
        await ReceiveMessagesAsync();
}
private static void ConnectionStatusChanges(ConnectionStatus status, ConnectionStatusChangeReason reason)
{
        MessageBox.Show($"Connection status changed - ConnectionStatus = {status}, ConnectionStatusChangeReason = {reason}");
}
area-documentation bug good first issue help wanted

Most helpful comment

@ynyang there is no support for the handler because HTTPS is connectionless (from the standpoint of our API - in reality connection-pooling is used within the HTTP stack). OpenAsync/CloseAsync are no-ops and the status is never changed.

Feel free to submit a PR to correct the documentation in both DeviceClient and ModuleClient to clarify that this has no effect for HTTP.

All 3 comments

@ynyang there is no support for the handler because HTTPS is connectionless (from the standpoint of our API - in reality connection-pooling is used within the HTTP stack). OpenAsync/CloseAsync are no-ops and the status is never changed.

Feel free to submit a PR to correct the documentation in both DeviceClient and ModuleClient to clarify that this has no effect for HTTP.

Closing this as I have now checked in some documentation to the connection status method that clarifies that it is not applicable to clients using HTTPS

@ynyang, @CIPop, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey

Was this page helpful?
0 / 5 - 0 ratings