从 .NET 客户端连接到 dotnet 核心中的 SignalR 服务器 [英] Connect to SignalR server in dotnet core from .NET client

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

问题描述

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

I have a signalR server implemented in Dotnet Core 2.0, below is the code for the server

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 方法中得到了它(它做了很多事情,然后应该通知客户端)

Then, in a controller I have got this in a GET Method (which does a bunch of stuff and then is supposed to notify clients)

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

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

Now for the .NET client (3.5) I have the following code

 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.

However, it throws an exception saying 404 Not Found.

推荐答案

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

You're using different versions of SignalR on your client and server.You can't mix and match versions of SignalR. You can look at the samples located at https://github.com/aspnet/SignalR/tree/dev/samples/ClientSample and https://github.com/aspnet/SignalR-samples to see how to get simple SignalR Core apps started.

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

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