情况:
SignalR服务是一项新功能,因此我们希望在 .net核心中编写此功能。 SignalR服务已启动并运行,我们可以从我们的核心项目连接如下(简化的控制台应用程序):
Console.WriteLine("Hello World!");
var connection = new HubConnectionBuilder()
.WithUrl("http://localhost:5123/myhub")
.WithConsoleLogger()
.Build();
connection.StartAsync().Wait();
connection.On<string>("send", data =>
{
Console.WriteLine($"Received: {data}");
});
Console.ReadLine();
connection.DisposeAsync().Wait();
只要我们留在.net核心世界,就没有问题。当我们尝试从 .net4.6 应用程序进行连接时,会出现此问题。
示例(也简化了控制台应用程序):
var connection = new HubConnection("http://localhost:5123/myhub");
var hub = connection.CreateHubProxy("myhub");
connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
{
Console.WriteLine("There was an error opening the connection: {0}", task.Exception.GetBaseException());
}
else
{
Console.WriteLine("Connected");
}
});
hub.On<string>("send", result =>
{
Console.WriteLine(result);
});
Console.Read();
connection.Stop();
我们使用完全相同的网址获取404未找到错误:
There was an error opening the connection: Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
X-SourceFiles: =?UTF-8?B?YzpcdXNlcnNcZ29ldGVsZW5kclxzb3VyY2VccmVwb3NcU2lnbmFsUlN0YXJ0ZXJcU2lnbmFsUlN0YXJ0ZXIuQVBJXG15aHViXHNpZ25hbHJcbmVnb3RpYXRl?=
Date: Wed, 15 Nov 2017 12:16:02 GMT
Server: Kestrel
X-Powered-By: ASP.NET
Content-Length: 0
}
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass5_0.<Get>b__1(HttpResponseMessage responseMessage)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass31_0`2.<Then>b__0(Task`1 t)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass3_0.<RunTask>b__0(Task`1 t)
主要问题是,是否可以从.net 4.6连接到.net核心signalR集线器?
答案 0 :(得分:2)
SignalR的早期版本与SignalR的Asp.NET Core版本不兼容。这意味着您无法将旧客户端与新服务器一起使用,反之亦然。新客户端的目标是netstandard 2.0,这意味着只要您running .NET Framework 4.6.1.
,就可以在完整.NET Framework上运行的应用程序中使用它