We are trying to use a standalone SignalR server and have a couple of hubs built that we are utilizing. They are working correctly, but I have been unable to get SignalR to utilize the WebSockets transport.
In general, I've had trouble finding current information on the requirements for getting SignalR to negotiate using WebSockets. Can someone help us figure out why WebSockets are not being used?
A little bit about our configuration:
- SignalR Server:
- "Microsoft.AspNet.SignalR": "2.2.1"
- Framework: net462
- Hosting:
- Azure App Services
- Web sockets: On
- CORS: Allowed Origins: *
- Pricing Tier: Basic: 1 Small
- .NET Framework version v4.6
- SSL certificate
- Azure App Services
We're using the most recent versions of Chrome and Edge as a JS client.
Here is some of our SignalR server configuration:
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>>();
}));
}
Negotiate response from SignalR server:
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 client initilization:
$.connection.hub.logging = true;
$.connection.hub.start({
transport: ['webSockets', 'longPolling'],
withCredentials: false
});
Full 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 Tools console messages:
[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.
Edit 4/26/2017
Per suggestion, I explicitly set the transport to be only webSockets transport:
$.connection.hub.logging = true;
$.connection.hub.start({
transport: ['webSockets'],
withCredentials: false
});
Here are the error messages:
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.