While I was testing my web solutions I found this type of error, this error did not happen to me when I executed the solutions in Visual Studio 2019 since when they were executed the connection was secure, but the error happened to me when the server (Blazor Server) tried to communicate a message to the client (Blazor WebAssembly), the client connected without any problem to Hub
the Blazor Server, but when it did so with the Http protocol without the SSL certificate, it did not allow the client to receive the message. NOTE: The "Client" was created with BlazorWebAssembly and is NOT hosted, they are two different solutions that interact with each other through WebSockets.
My code:
protected override async Task OnInitializedAsync()
{
await ConnectToServer();
}
public async Task ConnectToServer()
{
_connection = new HubConnectionBuilder().WithUrl(Globals.SignaR_Zones).Build();
connectionStatus = "Connected"; isConnected = true;
_connection.Closed += async (s) =>
{
isConnected = false;
connectionStatus = "Disconnected";
await _connection.StartAsync();
isConnected = true;
};
_connection.On<string>("realtime", m =>
{
StateHasChanged();
});
await _connection.StartAsync();
Show(Toaster, MatToastType.Success, "Your are now connected", "Connection");
}
To solve this type of problem was relatively easy, before executing the method that makes the client connect to the called server,
ConnectToServer()
I executed a method that basically bypassed the SSL certificate. I place this method inside the client in Program.cs , from there I call it from where I need it, in this case fromApp.razor
(it is where the method is initializedConnectToServer()
).It would be like this:
If it doesn't work that way try adding it before
connection.On
Source