从.NET客户端连接到dotnet核心的SignalR服务器

时间:2018-01-23 11:16:15

标签: .net .net-core signalr signalr-hub signalr.client

我有一个在Dotnet Core 2.0中实现的signalR服务器,下面是服务器的代码

Startup.cs

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
        services.AddSignalR ();
    }


    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseMvc();

        app.UseSignalR (routes => {
            routes.MapHub <NotificationsHub> ("notificationshub");                
        });
    }    

NotificationsHub.cs

public class NotificationsHub : Hub
{

}    

然后,在一个控制器中我得到了一个GET方法(它做了很多东西然后应该通知客户端)

_hubContext.Clients.All.InvokeAsync ("appointmentConfirmation",name,message);

现在对于.NET客户端(3.5),我有以下代码

 var APIURL = "https://localhost:11111/notificationshub"
 _notificationHub = new HubConnection(APIURL, false);                
 _notificationProxy = _notificationHub.CreateHubProxy("NotificationsHub");

 _notificationProxy.On<String,JObject>("appointmentConfirmation",
                                                 (name, message) =>
                                                 {
                                                     //
                                                 });
  await _notificationHub.Start();

然而,它引发了一个例外404 Not Found

1 个答案:

答案 0 :(得分:3)

您在客户端和服务器上使用不同版本的SignalR。您无法混合和匹配SignalR的版本。 您可以查看https://github.com/aspnet/SignalR/tree/dev/samples/ClientSample处的示例 和 https://github.com/aspnet/SignalR-samples 了解如何启动简单的SignalR Core应用程序。