我們正在嘗試使用獨立的SignalR服務器,並建立了一些我們正在使用的集線器。他們工作正常,但我一直無法讓SignalR利用WebSockets傳輸。SignalR不使用Websocket傳輸與ASPNET 4.6
一般來說,我很難找到有關獲取SignalR使用WebSocket進行協商的要求的最新信息。有人可以幫助我們弄清楚爲什麼WebSockets不被使用?
瞭解配置一點點:
- SignalR服務器:
- 「Microsoft.AspNet.SignalR」: 「2.2.1」
- 框架:net462
- 主機:
- 天青App Se rvices
- 網絡插座:在
- CORS:允許起源:*
- 定價等級:基礎:1小
- .NET Framework版本V4.6
- SSL證書
- 天青App Se rvices
我們使用最新版本的Chrome和Edge作爲JS客戶端。
下面是我們的一些SignalR服務器配置:
Startup.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
});
Full Web。配置:
<?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>
Google 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
});
這裏a重新顯示錯誤消息:
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.
我的web.config中沒有''',但我會嘗試明確地將其設置爲true。我也想推薦我的第一個問題,我的完整web.config –
本地運行IIS Express(Windows 10主機),我無法添加''或''看看我是否有任何行爲改變。實際上,我在WebSocketModule b/c上收到了500.19的錯誤,這在applicationHost.config中已經被定義爲true。我也用我的完整web.config文件更新了我的文章。 –
請將JS代碼中['webSockets']的傳輸值更改爲顯式使用webSockets。請檢查是否發生錯誤並提供詳細錯誤消息。 – Amor