connet to asp.net core signalR server from a javascript client

谁说我不能喝 提交于 2019-12-08 07:00:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!