gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:36:45 25 4
gpt4 key购买 nike

我有一个通过 .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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com