从javascript客户端连接到asp.net核心SignalR服务器 [英] connet to asp.net core signalR server from a javascript client

查看:133
本文介绍了从javascript客户端连接到asp.net核心SignalR服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net核心网络api服务器正在流式传输信号器,并且它适用于asp.net客户端,我正在尝试与显示如下的代码建立连接,但它仅连接到不会的非核心服务器为核心服务器工作.

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 
}

路由的启动代码:

 app.UseSignalR(routes =>
            {
                routes.MapHub<LogNotifierHub>("/NotifierHub");
            });

javascript 用于建立连接的代码

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); }); 

推荐答案

您不能混合使用SignalR服务器和客户端的版本.如果您在服务器上使用核心,则也必须在客户端上使用它.

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.

用于ASP.NET Core的SignalalR与SignalR的早期版本不兼容.这意味着您不能将旧服务器与新客户端一起使用,也不能将旧客户端与新服务器一起使用.

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.

这篇关于从javascript客户端连接到asp.net核心SignalR服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆