Is web socket supported in .NET Core ? throwing "S

2019-07-27 10:07发布

I have written console application using .NET Core 2.1.

The responsibility of this application is: Connect to the Azure IoT hub and send data.

I am still getting below exception

System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure. at System.Net.Security.SslState.StartSendAuthResetSignal

Note:

  • I am running my code on Windows Embedded Standard.
  • Using web sockets
  • Works fine in Windows 10

Here is my nuget references

   using Microsoft.Azure.Devices.Client;
   using Microsoft.Azure.Devices.Shared;

This is how I create connection.

   string deviceConnectionString = "*******";
  _Client = DeviceClient.CreateFromConnectionString(deviceConnectionString, TransportType.Mqtt_WebSocket_Only);

web sockets will not work on windows 7. Reference: Using WebSocket on Windows 7

So I am using .NET Core 2.1 to get web socket support, as mentioned here https://github.com/dotnet/corefx/issues/20191

Still I get the same error!

what does below means?

The remote certificate is invalid according to the validation?

Update

It seems the .NET runtime is not able to call the older Windows Embedded Standard APIs to validate the certificate for TLS. I may need to do that within mycode itself.

Some details are at https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support

The other option is to compile the C SDK, which already has this certificate for TLS. It can be called through our C# code. It will be compact and less dependency.

1条回答
爷、活的狠高调
2楼-- · 2019-07-27 10:54

Since I don't have a high enough rep to comment I'll provide this as an answer though it is more of a suggestion. I ran into a similar problem and needed to connect to an IoT hub from Windows Embedded. I didn't get as far as you since I also needed to use a web proxy and there was no way to do that with the C# SDK and .Net Core.

I went in the second direction that you mentioned and compiled the C SDK. Since my client did not have C experience, I built a C# P/Invoke wrapper around the C SDK dlls. Perhaps it will be of some use to you. You can find it here: https://github.com/markrad/IoTPInvoke

查看更多
登录 后发表回答