【发布时间】:2019-06-28 18:10:10
【问题描述】:
有时我的 signalr .net 客户端的 InvokeAsync 方法有效,有时无效。
我有一个 .net core 2.2 项目,它有一个 Azure signalR 服务中心,在我的 startup.cs 中我这样设置:
services.AddSignalR(o => o.EnableDetailedErrors =
true).AddAzureSignalR(connstring);
app.UseAzureSignalR(route =>
{
route.MapHub<FooBarHub>("/foobarhub");
});
我有一个 .net 客户端项目,它是一个 winform 应用程序 (.net 4.6.1),它设置了如下连接:
connection = new HubConnectionBuilder().WithUrl($"
{serviceHost}/AgentHub").Build();
当它启动时我调用:
await connection.StartAsync();
并且可以看到状态是 Connected。
然后我想从客户端调用集线器上的一个方法,所以我在客户端执行此操作:
string myIdString = await connection.InvokeAsync<string>
("RegisterSignalRId", foobarId);
这应该会在我的服务器集线器中使用我的方法:
public string RegisterSignalRId(string foobarId)
{
myService.RegisterSignalRId(this.Context.ConnectionId, foobarId);
return this.Context.ConnectionId;
}
我的问题是,有时当我启动 winform 应用程序时,我将 myIdString 设置为 null,它根本没有命中服务器集线器方法中的断点,但有时它确实有效,我得到了真正的 /正确的值。
我无法始终如一地让它工作或失败,这似乎是随机的。
【问题讨论】:
-
经过更多挖掘后,我认为这是因为我使用的是 Azure signalR 服务。我添加了一种新方法,有时会点击,有时会说 . HubException:方法不存在。
标签: signalr.client asp.net-core-signalr