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

编程入门 行业动态 更新时间:2024-10-26 21:28:57
本文介绍了从.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 = "localhost:11111/notificationshub" _notificationHub = new HubConnection(APIURL, false); _notificationProxy = _notificationHub.CreateHubProxy("NotificationsHub"); _notificationProxy.On<String,JObject>("appointmentConfirmation", (name, message) => { // }); await _notificationHub.Start();

但是,它抛出一个异常,表示未找到 404

However, it throws an exception saying 404 Not Found.

推荐答案

您在客户端和服务器上使用了不同版本的SignalR。您无法混合使用多个版本的SignalR。 您可以查看位于 https:// github上的示例。 com / aspnet / SignalR / tree / dev / samples / ClientSample 和 github/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 github/aspnet/SignalR/tree/dev/samples/ClientSample and github/aspnet/SignalR-samples to see how to get simple SignalR Core apps started.

更多推荐

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

本文发布于:2023-11-14 02:42:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586004.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   客户端   核心   服务器   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!