I'm using SignalR to communicate between my ASP.NET server and Xamarin.Forms client. However, when I'm using https, HubConnection throws this exception when trying to .StartAsync() : System.Net.Http.HttpRequestException: 'The SSL connection could not be established, see inner exception.
However, when I'm using http instead, all works fine.
Please, help me!
Thank you in advance!
So, I solved it by upgrading Xamarin.Forms shared project .NETStandard version to 2.1, and rewriting HubConnectionBuilder this way:
hubConnection = new HubConnectionBuilder().WithUrl(Properties.Resources.ServerIPAddress + "/test",
options =>
{
options.WebSocketConfiguration = conf =>
{
conf.RemoteCertificateValidationCallback = (message, cert, chain, errors) => { return true; };
};
options.HttpMessageHandlerFactory = factory => new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
};
options.AccessTokenProvider = () => Task.FromResult(Token);
}).Build();
hubConnection = new HubConnectionBuilder()
.WithUrl($"your host/chatHub", (opts) =>
{
opts.HttpMessageHandlerFactory = (message) =>
{
if (message is HttpClientHandler clientHandler)
// bypass SSL certificate
clientHandler.ServerCertificateCustomValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => { return true; };
return message;
};
}).Build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With