Connect to SignalR server in dotnet core from .NET client

一曲冷凌霜 提交于 2019-12-08 08:39:05

问题


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
{

}    

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

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

However, it throws an exception saying 404 Not Found.


回答1:


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.



来源:https://stackoverflow.com/questions/48400377/connect-to-signalr-server-in-dotnet-core-from-net-client

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