- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已在无服务器模式下创建了 Azure SignalR 服务。我在 Azure 函数应用程序中有一套函数来管理必须包含组的聊天服务。发布 Function App 时,我将 AzureSignalRConnectionString 设置为 SignalR 服务中 Keys 设置下的设置。我已在 Azure 门户中仔细检查连接字符串是否存在且正确。
我可以使用 Postman 成功调用 Azure 中的各个函数,并且可以在 Azure 门户中对此进行监控并查看日志消息等。
但是,如果我在客户端中使用 HubConnection 尝试调用函数,它不会到达那里。此外,Postman 成功发送的消息不会导致集线器触发接收。
因此可以看到以下使用 REST 接口(interface)的调用是从 Azure 门户执行的:
await client.PostAsync($"{baseUrl}/api/{group}/add/{userName}", new StringContent(string.Empty));
但是,使用 HubConnection 的以下调用不会触发相同的 Azure 函数:
await hubConnection.SendAsync("AddToGroup", group, userName);
其函数绑定(bind)是:
[FunctionName("AddToGroup")]
public static async Task<IActionResult> Run(
[HttpTrigger(
AuthorizationLevel.Anonymous,
"post",
Route = "{groupName}/add/{userId}")]
HttpRequest req,
string groupName,
string userId,
[SignalR(HubName = Constants.HubName)]
IAsyncCollector<SignalRGroupAction> signalRGroupActions,
ILogger log)
{
log.LogInformation("AddToGroup invoked");
await signalRGroupActions.AddAsync(
new SignalRGroupAction
{
UserId = userId,
GroupName = groupName,
Action = GroupAction.Add
});
return new OkObjectResult("All done");
}
函数应用程序包含一个协商函数,用于初始化集线器连接,如下所示:
var negotiateJson = await client.GetStringAsync($"{baseUrl}/api/negotiate");
var info = JsonConvert.DeserializeObject<NegotiateInfo>(negotiateJson);
hubConnection = new HubConnectionBuilder()
.WithUrl(info.Url, options =>
{
options.AccessTokenProvider = () => Task.FromResult(info.AccessToken);
})
.Build();
调试显示网址正确并且存在访问 token 。
我使用的是 Microsoft.AspNetCore.SignalR.Client V3.0.0,并遵循了许多指南和示例,但无法让 Azure SignalR 中心正常工作。
(我过去曾使用过托管 SignalR,发现它非常简单,但之前没有使用过 Azure 服务或 Azure Functions)。
我将永远感激任何帮助或指导。
谢谢
最佳答案
Azure SignalR 服务 + Azure Functions 支持通过 SignalR 从客户端向服务发送消息(使用 ASP.NET CORE)
服务器端(传统模型):
[FunctionName("notifyServerViaSignalR")]
public async Task NotifyServerViaSignalR([SignalRTrigger("YourHub", "messages", "NotifyServerViaSignalR")]
InvocationContext invocationContext, [SignalRParameter] string additionalParameter, ILogger logger)
{
logger.LogInformation($"Processed NotifyServerViaSignalR - AdditionalParameter:{additionalParameter} from ConnectionId:{invocationContext.ConnectionId}.");
}
同时在 Azure SignalR 设置中配置上游 URL
Function_App_URL 可以在 Function App 的概述页面上找到,API_KEY 由 Azure Function 生成。您可以从 Function App 的应用 key 边栏选项卡中的 signalr_extension 获取 API_KEY。
客户端:
connection.invoke("NotifyServerViaSignalR",additionalParameter);
关于c# - SignalR HubConnection 未从无服务器 Azure SignalR 服务接收消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58997261/
我正在使用 SignalR 版本 2.2.0。使用下面的代码,我得到一个异常,指出 $ 没有定义 hubConnection。我知道我的脚本路径是正确的,因为我可以在信号脚本中设置断点并查看它们是否被
我的 SignalR 项目遇到了问题。我创建了一个控制台来运行 SignalR,然后尝试在我的网站上使用它(目前都以 localhost 模式运行) SignalRSSelfHost using Sy
我用以下代码构建了一个通知系统: class SignalRClient { HubConnection hubconn; IHubProxy proxy; public Si
我正在尝试在基于 an example over here 的 ASP.NET MVC 4 应用程序中实现聊天模块。由于这个没有使用最新的 SignalR 版本 (0.5.3),我必须调整代码才能使其
两者有什么区别 this.hubConnection = new signalR.HubConnectionBuilder() .withUrl(environment.API_URL + "in
在 AspNet SignalR 客户端中,是否需要处理 HubConnection 操作? 从我所看到的来看,这似乎需要一些时间...... 最佳答案 如果您调用 Stop(),则不需要。 参见ht
两者有什么区别 this.hubConnection = new signalR.HubConnectionBuilder() .withUrl(environment.API_URL + "in
大家好,我正在致力于使用基于 example over here 的 AngularJS 实现 SignalR 股票行情自动收录器。但是我在连接到信号器时遇到错误,如下所示 TypeError: $.
嗨,我是 android 开发的新手,我想编写一个使用 signalR java 客户端的应用程序。在第一步中,我做了 this 的答案这是我的客户端代码: Platform.loadPlatform
根据我发现的一个例子,http://weblog.west-wind.com/posts/2013/Sep/04/SelfHosting-SignalR-in-a-Windows-Service ,我
我有一个带有 signalR 的 ASPNet.Core WebApi。我有使用 webAPI 的 angular 应用程序,我想用 Blazor Webassembly 应用程序替换它。我在 Bla
我在 Android 中从事 SignalR 实现工作。在第一步中,它很容易连接。重新打开应用程序后,它因记录错误而崩溃。集线器连接已连接 Platform.loadPlatformComponen
我们已经编写了一个原型(prototype)来测试 SignalR 的性能,以检查我们是否可以将它用于我们的软件。在该原型(prototype)中,我们测试了两者,通过 PersistentConne
我正在尝试使用 powershell 脚本连接到 SignalR 集线器。我是 Powershell 的新手,所以请原谅任何菜鸟错误。 我已经设置了一个最小的 not 工作示例来说明我在这里尝试过的内
我正在查看 unit tests对于 SignalR 并注意到其中一项测试使用 Moq 创建模拟 HubConnection: [Fact] public void HubCallbackCleare
我已在无服务器模式下创建了 Azure SignalR 服务。我在 Azure 函数应用程序中有一套函数来管理必须包含组的聊天服务。发布 Function App 时,我将 AzureSignalRC
我正在尝试将参数添加到信号器的连接中。 我正在使用 Builder 创建我的客户端连接并启动它: var connection = new HubConnectionBuilder()
我正在尝试实现一个 Angular 和信号器项目。我从 Medium 获取样本 我已经安装了所有必要的包,并且在 app.component.ts 中有以下代码: import { Component
我的 Blazor WebAssembly 应用程序中有一个 SignalR HubConnection,虽然它大部分时间都在工作,但如果我重新加载页面(通过浏览器重新加载),那么我经常会在控制台并且
我用 Angular6 开发了一个项目。需要开发实时聊天部分。为此,我在我的 asp.net core Web Api 项目中使用 SignalR。现在我想在我的 Angular 项目中使用此 Web
我是一名优秀的程序员,十分优秀!