reactjs - 将应用程序 react 到 Azure SignalR - FailedWritingMessageToServiceException : Unable to write message to endpoint: https://xxx-dev. service.signalr.net/

标签 reactjs azure asp.net-core react-hooks signalr

我有一个通过 .NET CORE API 连接到 Azure Signal R 服务的 React 应用程序。当 react 应用程序启动时,我收到一条消息,表示它已成功连接到集线器,但它立即出错,并显示消息“在服务器上调用‘GetData’时发生意外错误”。 FailedWritingMessageToServiceException:无法将消息写入端点:https://xyz-dev.service.signalr.net/' .

请注意,如果我删除 AddAzureSignalR() 依赖项,它会连接到集线器并成功连续提取数据约 250 次,然后它将无故自动断开连接。

我已经在 useEffect Hook 中设置了与 api 的连接,如下所示

try {
        const connection_ = new HubConnectionBuilder()
          .withUrl("https://localhost:44368/hubs", {
            skipNegotiation: true,
            transport: HttpTransportType.WebSockets,
          })
          .withAutomaticReconnect()
          .configureLogging(LogLevel.Information)
          .build();

        connection_.on("DataReceived", (x, y, z) => {
         setData({
            ...data,
            x: x,
            y: y,
            z: z,
    
          });
        });

    await connection_.start();
    await connection_.invoke("GetData", location.state.id);
}
catch(e) {
console.log(e);
} 

在.NET CORE配置服务中,我添加了如下依赖项。

services.AddSignalR(hubOptions =>
        {
     hubOptions.EnableDetailedErrors = true;
     hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(2);
     hubOptions.ClientTimeoutInterval = TimeSpan.FromMinutes(2);
     }).AddAzureSignalR(_config.GetConnectionString("AzureSignalR"));

    app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
            endpoints.MapHub<SensorHub>("/hubs");
        });

非常感谢对此的任何帮助。

谢谢

最佳答案

我今天也遇到了这个错误,我仔细检查了所有Azure SignalR设置,经过一些测试,我发现我需要使用默认服务模式

编辑: 更改服务模式步骤:

新的 Azure SignalR 服务,“基本”选项卡,“服务模式”字段,将其保留为默认值

到现有的 Azure SignalR 服务

  1. 设置 Blade
  2. 将服务模式更改为默认

关于reactjs - 将应用程序 react 到 Azure SignalR - FailedWritingMessageToServiceException : Unable to write message to endpoint: https://xxx-dev. service.signalr.net/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73065057/

相关文章:

javascript - ReactJS:Express API 和 ReactJS 结构限制每行显示数据

javascript - React router - 在我刷新浏览器之前页面不会呈现

azure - 更新 Azure Service Fabric 证书。为什么要初级证书和二级证书?

azure - 如何通过Azure vm访问Bitnami中的物理UI层magento根目录

c# - 找不到项目文件

javascript - yarn 工作区和无效的 Hook 调用

reactjs - 在 Next.js 应用程序中使用 GraphQL 的推荐方法

c# - 尝试使用启动文件中的 GetSection 访问它们时,配置值为空。(IOptions-config 检索)

c# - .NET Core Xunit - IActionResult' 不包含 'StatusCode' 的定义

nhibernate - ASP.NET 5 NHibernate session 需要 System.Data.IDbConnection?