I have a self-hosted WebAPI web service using a self-signed certificate. I am successfully able to communicate with the web service controller actions from other applications using the URL:
https://localhost:5150/...
Note that I have successfully bound the self-signed certificate to port 5150 and reserved the port for all IPs for my application, both by using the appropriate netsh commands.
I am trying to integrate a SignalR hub into this web service. I configure the hub, with CORS support, using the following in my startup code:
// Configure the SignalR hub that will talk to the browser
appBuilder.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
HubConfiguration hubConfig = new HubConfiguration();
hubConfig.EnableDetailedErrors = true;
hubConfig.EnableJavaScriptProxies = false;
map.RunSignalR(hubConfig);
});
I am starting up my HTTP listener, which is/was also used for Web API by this:
_webApp = WebApp.Start<Startup>(baseUrl);
where the baseUrl is
https://+:5150/.
My SignalR initialization code, in my Angular controller is:
var initialize = function () {
//Getting the connection object
connection = $.hubConnection("/signalr", { useDefaultPath: false });
// Url signalr scripts should hit back on the server
connection.url = ENV.SIGNALR.protocol + '://' + ENV.SIGNALR.server + ':' + ENV.SIGNALR.port + '/' + ENV.SIGNALR.url;
// Turn on client-side logging
connection.logging = ENV.SIGNALR.logging;
// Get proxy based on Hub name (must be camel-case)
proxy = connection.createHubProxy('dashboardHub');
// Setup event handlers for messages we get from the server.
proxy.on('rxDiagnosticMessage', function (msg) {
//console.log('Received rxDiagnosticMessage');
$rootScope.$broadcast("rx-diagnostic-message", msg);
});
//Starting connection
connection.start()
.done(function () { console.log('SignalR connection started'); })
.fail(function (err) { console.log('SignalR connection failed - ' + err); });
// Display errors to console
connection.error(function (err) {
console.log('SignalR error - ' + err);
});
};
When the connection to the hub is attempted, I get the following error:
15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Auto detected cross domain url. jquery.signalR-2.1.0.js:81
[15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'dashboardhub'. jquery.signalR-2.1.0.js:81
[15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with 'https://localhost:5150/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22dashboardhub%22%7D%5D'. jquery.signalR-2.1.0.js:81
GET https://localhost:5150/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22dashboardhub%22%7D%5D&_=1407524683014 net::ERR_INSECURE_RESPONSE jquery-2.1.1.js:8623
SignalR error - Error: Error during negotiation request. AppSignalR.js:43
SignalR connection failed - Error: Error during negotiation request. AppSignalR.js:39
[15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Stopping connection.
Note the net::ERR_INSECURE_RESPONSE during the SignalR connection negotiation.
Strange thing...if I run Fiddler2 then the connection works! (Is Fiddler serving up a nice certificate to my web app / SignalR?)
I suspect this is due to the certificate being self-signed (cert in Personal, cert authority in Trusted). In WCF and WebAPI clients I always intercept the authority errors and bypass the error:
ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
Is there something similar that needs to be done in the SignalR client in my Angular application? Or should this just work?
Note that I have seen this thread - SignalR with Self-Signed SSL and Self-Host still does not work for me.