I have an ASP.NET Core web API with a SignalR Hub and a .NET Core console app that acts as a client for the hub.
The console app throws the following error when trying to connect:
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers:
{
Date: Mon, 20 May 2019 18:12:44 GMT
Server: Kestrel
Content-Length: 0
})
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at SurveyApp.NotificationClient.Program.Main(String[] args) in C:\Users\user\source\repos\SurveyApp\SurveyApp.NotificationClient\Program.cs:line 16
Inner Exception 1:
HttpClientException: StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers:
{
Date: Mon, 20 May 2019 18:12:44 GMT
Server: Kestrel
Content-Length: 0
}
I have tried all kinds of renaming of routes and hubs, but it still doesn't work. Also tried the solution shown here since it is a similar issue, but still not result: HttpClientException when connecting to working hub from SignalR .NET Client
Server: DI registration:
services.AddSignalR();
Middleware registration:
...
app.UseSignalR(route =>
{
route.MapHub<NotificationHub>("/notificationhub");
});
app.UseMvc();
Hub class:
public class NotificationHub : Hub
{
public Task SendMessage(string message)
{
return Clients.All.SendAsync(message);
}
public override Task OnConnectedAsync()
{
Console.WriteLine("A client connected");
return base.OnConnectedAsync();
}
}
Client code:
static void Main(string[] args)
{
var connection = new HubConnection("https://localhost:5001/notificationhub");
connection
.CreateHubProxy("NotificationHub")
.On<string>("ReceiveNotification", Console.WriteLine);
connection.Start().Wait();
Console.WriteLine("Connection started");
Console.ReadKey();
}
When I don't call Wait() after connection.Start(), I do not get any error, but the client still doesn't connect. I'm running .NET Core 2.2 both on the server and the client and the version for the SignalR nuget is 2.4.1