【问题标题】:InvokeAsync is intermittentInvokeAsync 是间歇性的
【发布时间】: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


【解决方案1】:

所以答案是我已经签入(到源代码控制)我的天蓝色服务的连接字符串,所以其他开发人员也在使用它并将他们的 API 服务版本指向该天蓝色服务。因此,当我运行我的代码时,有时 azure 会使用新方法访问我的 API 服务并且它会工作,有时它会访问其他人的 api 并因此失败,因为他们的代码没有新方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 2021-07-15
    • 2012-10-20
    • 2018-12-16
    • 2019-01-18
    • 1970-01-01
    相关资源
    最近更新 更多