If you missed the announcement the other day, WebSockets are now supported in Windows Azure Web Sites.
Let's try it with a sample SignalR application.
Create an Azure Web Site
- Login to http://manage.windowsazure.com/
- Select New, Compute, Web Site, Quick Create
- Type a URL and click Create Web Site
- Go to Dashboard of your new website, click Download the publish profile, and save *.PublishSettings file on your local hard drive
Create a Visual Studio Project associated to an Azure Web Site
- Install Azure SDK for Visual Studio 2013
- Open Visual Studio 2013
- On Menu: select File, New, Project, Visual C#, Web, ASP.NET Web Application
- On Name, type "AzureWebSiteWithWebSockets", click OK
- Select Empty, click OK
- In the Solution Explorer, right-click on your project and select Publish
- Click Import, select Import from a publish profile file, click Browse
- Find the *.PublishSettings file and click OK
- Click Validate Connection
- Click Publish
Add SignalR Stock Ticker Sample
- In the Solution Explorer, right-click on your project, select Manage NuGet Packages
- Select Online
- On search box, type Microsoft.AspNet.SignalR.Sample
- Click Install
- On License Acceptance window, click I Accept
- Click Close
- In the Solution Explorer, right-click on your project, select Add, New Item
- Select Web, OWIN Startup class
- On Name, type "Startup.cs"
- Click Add
- On Startup.cs file, add this line of code inside method
"public void Configuration(IAppBuilder app)"Microsoft.AspNet.SignalR.StockTicker.Startup.ConfigureSignalR(app);
- On SignalR.Sample/SignalR.StockTicker.js file, add this line of code before "$.connection.hub.start()"
$.connection.hub.logging = true;
- In the Solution Explorer, right-click SignalR.Sample/StockTicker.html and select View in Browser
- Click Open Market. You should see animations on the table.
Publish your local changes to Azure Web Site
- Right click project, select Publish
- Click Publish
- On Browser, open http://[YourWebSite].azurewebsites.net/SignalR.Sample/StockTicker.html
- Click F12 to open the Web Developer Console
- Refresh page
- Your browser does not connect using websockets. It connects with another transport like Server Sent Events, Forever Frame, or Long Polling.
Enable WebSocket on Azure Web Site
- On Azure Portal, select Web Sites, select your Web Site, select Configure
- Find Web Sockets and turn it on
- Click Save
- On Browser, open http://[YourWebSite].azurewebsites.net/SignalR.Sample/StockTicker.html
- Click F12 to open the Web Developer Console
- Refresh page
- Your browser now connects using websockets!