use*_*107 1 .net c# signalr signalr.client asp.net-core-signalr
我有一个 SignalR 客户端,它似乎在启动后立即关闭,我得到的错误消息是:
“服务器关闭连接,出现以下错误:连接关闭,出现错误。InvalidOperationException:序列不包含元素”
SignalR 客户端用于 ASP.Net Core Web API 项目(在 API 控制器内)。
我使用的 Nuget 包称为 Microsoft.AspNetCore.SignalR.Client (v 1.1.0)
我的代码如下所示:
try
{
//SEND MESSAGE TO HUB
var connection = new HubConnectionBuilder()
.WithUrl("https://sample.azurewebsites.net/ChatHub")
.Build();
connection.Closed += async (error) =>
{
//log error - this is getting called straight after StartAsync
};
await connection.StartAsync();
await connection.InvokeAsync("SendToATeam", "x", "y");
await connection.StopAsync();
}
catch (Exception ex)
{
//log error
}
Run Code Online (Sandbox Code Playgroud)
在您的服务器上,您可以通过以下方式打开详细错误:
services.AddSignalR(o =>
{
o.EnableDetailedErrors = true;
})
Run Code Online (Sandbox Code Playgroud)
这将在客户端上为您提供更详细的错误消息
| 归档时间: |
|
| 查看次数: |
1849 次 |
| 最近记录: |