SignalR不使用Websocket传输与ASPNET 4.6

问题描述:

我们正在尝试使用独立的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证书

我们使用最新版本的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. 

我无法根据您的描述重现问题。我可以在Azure Web App上使用ASPNET 4.6的Websocket Transport。

“TryWebSockets”:假,

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

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

更新2017年5月2日

由于您使用OWIN,请检查您是否已经添加以下代码Startup.Configure方法使用Web袜子。

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

我的web.config中没有''',但我会尝试明确地将其设置为true。我也想推荐我的第一个问题,我的完整web.config –

+0

本地运行IIS Express(Windows 10主机),我无法添加''或''看看我是否有任何行为改变。实际上,我在WebSocketModule b/c上收到了500.19的错误,这在applicationHost.config中已经被定义为true。我也用我的完整web.config文件更新了我的文章。 –

+0

请将JS代码中['webSockets']的传输值更改为显式使用webSockets。请检查是否发生错误并提供详细错误消息。 – Amor