我是 SignalR 的新手,我正在尝试在 .net 控制台上设置一个服务器,我将在 Win 服务器 2012 中执行它。我在 YouTube/Google 等网站上花了大约 3 天,但在我执行时无法处理服务器在不同的电脑上。在我的电脑上,我可以成功连接客户端和服务器。
我的目标是通过 MS SQL、Entity-framework 7 和 net core 7 中的 Winforms 中的不同客户端获得实时更新,服务器(不关心是 .net Framework 还是 .net core)。
我在服务器端有这段代码:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
using serverPTP.Hubs;
using Microsoft.Extensions.Logging;
class Program{
static void Main(string[] args)
{
try
{
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
EnvironmentName = Environments.Production
});
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Services.AddSignalR();
var app = builder.Build();
app.Urls.Add("http://localhost:some port");
app.MapHub<HubPTP>("/Hubs/HubPTP");
app.UseHsts();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
Console.WriteLine("3 seg for RUN:");
Thread.Sleep(3000);
app.Run();
Console.WriteLine("Continue..");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine(ex.StackTrace);
if(ex.InnerException != null)
{
Console.WriteLine(ex.InnerException.ToString());
}
}
}
}
如果我运行这个应用程序可以工作,如果我在我的电脑上安装这个应用程序可以工作但在我的 Windows 服务器 2012 中不工作。我没有错误消息,只是在 app.Run() 关闭控制台之后... 代码有什么问题?
我正在使用 NuGet 包 Microsoft.AspNetCore.SignalR.Client 7.0.3