问题
I have asp.net core web api server that is streaming a signalr, And it works for asp.net client , I am trying to make a connection with the code showen beelow but it only connects to a none core servers it wouldnt work for the core servers.
//the hub class in the server code
[EnableCors("AllowAllOrigins")]
[HubName("LogNotifierHub")]
public class LogNotifierHub : Hub
{
//methods defined here
}
startup code for the routing :
app.UseSignalR(routes =>
{
routes.MapHub<LogNotifierHub>("/NotifierHub");
});
javascript code for making the connection
var hubUrl ="http://localhost:52273/logNotifierHub";
var connection = $.hubConnection(hubUrl, { useDefaultPath: true});
var hub = connection.createHubProxy("LogNotifierHub");
hub.on('SendStreamInit', function(data){
console.log( data)
})
connection.start()
.done(function(){ console.log(' connected!! connection ID=' + connection.id); })
.fail(function(error){ console.log('Could not connect!!' + error); });
回答1:
You can't mix and match version of the SignalR server and client. If you're using core on the server then you have to use it on the client as well.
From the MSDN SignalR alpha blog post
SignalR for ASP.NET Core is not compatible with previous versions of SignalR. This means that you cannot use the old server with the new clients or the old clients with the new server.
来源:https://stackoverflow.com/questions/49300820/connet-to-asp-net-core-signalr-server-from-a-javascript-client