从.NET客户端连接到dotnet核心中的SignalR服务器 [英] Connect to SignalR server in dotnet core from .NET client
问题描述
我有一个在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 。
However, it throws an exception saying 404 Not Found
.
推荐答案
您在客户端和服务器上使用了不同版本的SignalR。您无法混合使用多个版本的SignalR。
您可以查看位于 https:// github上的示例。 com / aspnet / SignalR / tree / dev / samples / ClientSample
和
https://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屋!