Language

Using SignalR with Windows Azure Web Sites

By Patrick Fletcher|

This document describes how to configure a SignalR application that runs on Windows Azure.

Software versions used in the tutorial


Questions and comments

Please leave feedback on how you liked this tutorial and what we could improve in the comments at the bottom of the page. If you have questions that are not directly related to the tutorial, you can post them to the ASP.NET SignalR forum or StackOverflow.com.

Table of Contents

Introduction

ASP.NET SignalR can be used to bring a new level of interactivity between servers and web or .NET clients. When hosted in Windows Azure, SignalR applications can take advantage of the highly available, scalable, and performant environment that running in the cloud provides.

Deploying a SignalR application to an Azure Web Site

SignalR doesn't add any particular complications to deploying an application to Windows Azure versus deploying to an on-premise server. An application that uses SignalR can be hosted in Windows Azure without any changes in configuration or other settings (though for SLA eligibility, see Using the Windows Azure Backplane below, and for Web Sockets support, see Enabling Web Sockets on Windows Azure Web Sites below.) For this tutorial, you'll deploy the application created in the Getting Started Tutorial to Windows Azure.

Prerequisites

  • The Windows Azure SDK for Visual Studio 2013. You can get this SDK here.

  • Visual Studio 2013. If you don't have Visual Studio 2013, it is included in the install of the Windows Azure SDK.

  • To complete this tutorial, you will need a Windows Azure subscription. You can sign up for a trial subscription to Windows Azure from the Windows Azure free trial page.

Deploying a SignalR application to Windows Azure

  1. Complete the Getting Started Tutorial, or download the finished project from Code Gallery".

  2. To publish the application to Windows Azure, follow the steps in the Deploy the application to Windows Azure section of the Get started with Windows Azure and ASP.NET tutorial.

Redeploying a SignalR application to Windows Azure

When updating a live application, existing connections and application data will not be maintained unless they are stored in a persistent data store, such as a Windows Azure table. For a code example demonstrating storing connection information in a Windows Azure table, see Mapping SignalR Users to Connections: Windows Azure.

Enabling Web Sockets on Windows Azure Web Sites

Web Sockets support is available on Windows Azure Web Sites. In order to use Web Sockets on Windows Azure Web Sites, it will need to be enabled in the configuration section of the site. To do this, open your web site in the Windows Azure Management Console, and select Configure.

Configure tab

At the top of the configuration page, ensure that .NET 4.5 is used for your web site.

.NET framework version 4.5 setting

On the configuration page, in the Web Sockets setting, select On.

Web Sockets setting: On

At the bottom of the Configuration page, select Save to save your changes.

Save settings

Using the Windows Azure Service Bus Backplane

If you use multiple instances for your web site, and the users of those instances need to interact with one another (so that, for instance, chat messages created in one instance can reach the users connected to other instances), the Azure Service Bus must be implemented in your application.

Implementing the Azure Service Bus backplane in SignalR

To enable the Azure Service Bus backplane in a SignalR application, follow these steps.

  1. Add the Microsoft.AspNet.SignalR.ServiceBus package to your project using the following command in the Library Package Manager Console:

    Install-Package Microsoft.AspNet.SignalR.ServiceBus
  2. Add the highlighted line below to the Configuration method of your OWIN startup class.

    public void Configuration(IAppBuilder app)
    {
        string connectionString = "Service Bus connection string";
        GlobalHost.DependencyResolver.UseServiceBus(connectionString, "YourAppName");
    
        app.MapSignalR();
    }

With this setting enabled, messages received by each instance will also be sent to the backplane. For information on how to send messages from the server directly to the backplane (from outside the hub), see How to call client methods and manage groups from outside the Hub class.

For more information on using the Windows Azure backplane, see SignalR Scaleout with Azure Service Bus.

Troubleshooting common issues with SignalR and Azure

Some messages are not received in multiple-instance application

If the Windows Azure Service Bus backplane is not implemented, or not implemented properly, messages generated in one instance will not be able to reach clients connected to other instances. For information on setting up the Windows Azure Service Bus backplane, see Using the Windows Azure Service Bus Backplane.

Messages are not received through the SignalR Windows Azure Service Bus Backplane after altering topic names

The topics used by the Windows Azure Service Bus Backplane are maintained internally; they are not intended to be user-configurable.

Messages are not received from hubs in different assemblies through the SignalR Windows Azure Service Bus Backplane

Hubs that communicate between instances of the backplane must be instances of the same hub class, defined in the same assembly. Hubs defined in different assemblies will not be able to communicate with one another through the backplane.

Author Information

Patrick Fletcher

Patrick Fletcher – Patrick Fletcher is a programmer-writer on the ASP.NET team, currently working on SignalR.