【问题标题】:Connect to SignalR server in dotnet core from .NET client从 .NET 客户端连接到 dotnet 核心中的 SignalR 服务器
【发布时间】:2018-01-23 11:16:15
【问题描述】:

我有一个在 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

【问题讨论】:

  • 协议是HTTPS对还是应该是HTTP?
  • SignalR for .NET Core 完全重写,尚未发布。可用的仍然是测试版。它也与旧版本不兼容
  • 此外,新客户的目标是.NET Standard 2.0。 .NET 3.5 甚至不再支持,最早支持的 .NET 版本是 4.5.2。最高 4.7 的版本需要 .NET Standard 2.0 库的附加包。 4.7.1 具有内置支持。如果你想使用 SignalR for .NET Core,你应该升级到 .NET 4.7.1

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 2021-06-03
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多