gpt4 book ai didi

azure - SignalR 不使用 ASPNET 4.6 的 Websocket 传输

转载 作者:行者123 更新时间:2023-12-02 07:28:55 31 4
gpt4 key购买 nike

我们正在尝试使用独立的 SignalR 服务器,并构建了几个我们正在使用的集线器。它们工作正常,但我无法让 SignalR 使用 WebSockets 传输。

总的来说,我很难找到有关让 SignalR 使用 WebSocket 进行协商的要求的最新信息。有人可以帮助我们找出为什么没有使用 WebSocket 吗?

关于我们的配置的一些信息:

  • SignalR 服务器:
    • “Microsoft.AspNet.SignalR”:“2.2.1”
    • 框架:net462
  • 托管:
    • Azure 应用服务
      • 网络套接字:开启
      • CORS:允许的来源:*
      • 定价等级:基本:1 小
      • .NET Framework 版本 v4.6
      • SSL 证书

我们使用最新版本的 Chrome 和 Edge 作为 JS 客户端。

以下是我们的 SignalR 服务器配置的一些内容:

启动.cs

app.UseOwinAppBuilder(map =>
{
map.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
HubConfiguration hubConfiguration = new HubConfiguration
{
EnableDetailedErrors = hubConfig.EnableDetailedErrors.Value,
};
map.MapSignalR("/signalr", hubConfiguration);
});


public static IApplicationBuilder UseOwinAppBuilder(this IApplicationBuilder app, Action<IAppBuilder> configuration)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}

if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

return app.UseOwin(setup => setup(next =>
{
AppBuilder builder = new AppBuilder();
IApplicationLifetime lifetime = (IApplicationLifetime)app.ApplicationServices.GetService(typeof(IApplicationLifetime));
IServiceProvider serviceProvider = (IServiceProvider)app.ApplicationServices.GetService(typeof(IServiceProvider));
IHostingEnvironment hostingEnv = (IHostingEnvironment)app.ApplicationServices.GetService(typeof(IHostingEnvironment));

AppProperties properties = new AppProperties(builder.Properties);
properties.AppName = hostingEnv.ApplicationName;
properties.OnAppDisposing = lifetime.ApplicationStopping;
properties.DefaultApp = next;

configuration(builder);

return builder.Build<Func<IDictionary<string, object>, Task>>();
}));
}

协商来自 SignalR 服务器的响应:

https://customdomain/signalr/negotiate?clientProtocol=1.5&connectionData=[{"name":"hubname"}]

{
"Url": "/signalr",
"ConnectionToken": "MTY5ODlmZmItMDUxNC00ZmJhLTgzZjMtOTcyOGM5ZTUxY2IwOg==",
"ConnectionId": "16989ffb-0514-4fba-83f3-9728c9e51cb0",
"KeepAliveTimeout": 20,
"DisconnectTimeout": 30,
"ConnectionTimeout": 110,
"TryWebSockets": false,
"ProtocolVersion": "1.5",
"TransportConnectTimeout": 5,
"LongPollDelay": 0
}

JS客户端初始化:

$.connection.hub.logging = true;
$.connection.hub.start({
transport: ['webSockets', 'longPolling'],
withCredentials: false
});

完整的 Web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime targetFramework="4.6"/>
<compilation targetFramework="4.6" strict="true">
</compilation>
</system.web>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>

Chrome 工具控制台消息:

[19:05:22 GMT-0400 (Eastern Daylight Time)] SignalR: Fired ajax abort async = false.
[19:05:22 GMT-0400 (Eastern Daylight Time)] SignalR: Auto detected cross domain url.
[19:05:22 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'concurrentaccesshub'.
[19:05:22 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with 'https: //customdomain/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22concurrentaccesshub%22%7D%5D'.
[19:05:22 GMT-0400 (Eastern Daylight Time)] SignalR: longPolling transport starting.
[19:05:23 GMT-0400 (Eastern Daylight Time)] SignalR: Opening long polling request to 'https: //customdomain/signalr/connect?transport=longP…Og%3D%3D&connectionData=%5B%7B%22name%22%3A%22concurrentaccesshub%22%7D%5D'.
[19:05:23 GMT-0400 (Eastern Daylight Time)] SignalR: Long poll complete.
[19:05:23 GMT-0400 (Eastern Daylight Time)] SignalR: LongPolling connected.
[19:05:23 GMT-0400 (Eastern Daylight Time)] SignalR: longPolling transport connected. Initiating start request.
<小时/>

编辑2017年4月26日

根据建议,我明确将传输设置为仅 webSockets 传输:

$.connection.hub.logging = true;
$.connection.hub.start({
transport: ['webSockets'],
withCredentials: false
});

以下是错误消息:

SignalR: Auto detected cross domain url.
SignalR: Client subscribed to hub 'concurrentaccesshub'.
SignalR: Negotiating with 'http: //localhost:56637/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22concurrentaccesshub%22%7D%5D'.
SignalR: No transports supported by the server were selected.
SignalR: Stopping connection.

最佳答案

根据您的描述,我无法重现该问题。我可以在 Azure Web App 上将 Websocket 传输与 ASPNET 4.6 结合使用。

"TryWebSockets": false,

此响应意味着 webSocket 在服务器端被禁用。 webSocket 也可以在 web.config 中禁用。请检查您的Web配置文件是否包含以下部分。

<system.webServer>
<webSocket enabled="false"/>
</system.webServer>

更新于 2017 年 5 月 2 日

由于您使用的是OWIN,请检查您是否在Startup.Configure方法中添加了以下代码来使用web sock。

public void Configure(IApplicationBuilder app)
{
app.UseWebSockets();
app.UseSignalR();
}

关于azure - SignalR 不使用 ASPNET 4.6 的 Websocket 传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43553504/

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