Scenario 8 : ASP.NET SignalR application is not working in azure cloud service

Referring to my blog on Azure Cloud Service Troubleshooting Series, this is the 8th scenario of the lab. Please make sure you have followed the lab setup instructions for Visitor Tracker application as per this, to recreate the problem.

 

Symptom

Visitor Tracker is an ASP.NET SignalR application which tracks the number of visitors accessing the website. Each user is given a unique tracking id which is displayed on the browser as the user moves the mouse pointer. As new users keep on visiting the site, the other users will be able to see new tracking ids on their browsers. Click on the below image to get an idea of the expected output.

Visitor-Tracking

But after few days the application stopped working i.e users are not able to see their tracking ids as well as for the other users on the browser.

 

Troubleshooting

SignalR uses the WebSocket transport where available, and falls back to older transports (Server Sent Events, Forever Frame (for Internet Explorer only), Ajax long polling) where necessary - This is known as SignalR transport negotiation. Refer this article to know more. You can determine what transport your application is using by taking a fiddler or F12 browser trace. Let's see what we can find in F12 developer trace...

Transport-Negotiation

From the above developer trace, we can see that client tried to connect over number of transports but all of them failed with 404 error. I would like to inspect the server response for the first negotiate request for which we got HTTP 200 response.

Request URL : https://cloudservicelabs.cloudapp.net:81/tracker/negotiate?clientProtocol=1.3&\_=1534347303083

Response {
"Url": "/tracker",
"ConnectionToken": "w9ppacqBDsP/uF90AZ97VYm6L+PYAz03iQPlEiU0uIwSZwEDXih+XHb0PV/FO9T+/22xmJp+St+tDlDg/cMUy1U9Of382YCNa94RYOOpRmsm8MNofd2eLpPNDFfaXAiM",
"ConnectionId": "4e81868d-dd9e-44ac-9b76-0f04da1f71c9",
"KeepAliveTimeout": 20,
"DisconnectTimeout": 30,
"ConnectionTimeout": 110,
"TryWebSockets": false,
"ProtocolVersion": "1.3",
"TransportConnectTimeout": 5,
"LongPollDelay": 0
}
From the above network trace it's quite clear that client tried to connect over WebSocket but Server doesn't support it. Also note that for SignalR to use WebSocket, IIS 8 must be used, the server must be Windows Server 2012, or later, and WebSocket must be enabled in IIS. We are using Windows Server 2016 but we need to check if WebSocket is enabled in IIS or not. In order to confirm that I logged in to one of the instance and opened Add Roles and Features Wizard from Server Manager. Expanded Web Server (IIS) role and found that WebSocket protocol was not enabled. :-)

 

Websocket-Feature

In order to enable WebSocket feature you can use the below DISM command in a startup task, so that when the role starts it installs the WebSocket feature in IIS.

%SystemRoot%\system32\DISM.exe /Online /Enable-Feature /FeatureName:IIS-WebSockets

 

I hope you have got an idea how to enable WebSocket protocol feature in Azure Cloud Service.

Happy Learning !