【发布时间】: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