SignalR with Azure Service Bus
Step 1 : Setup Azure Cloud Services
- Login to Azure
- Click CLOUD SERVICES and Choose +NEW
- Choose COMPUTE > CLOUD SERVICE > Quick Create > Url > MySignalr.Cloud.Service
- Choose the correct hosting region
Step 2 : Setup Azure Service Bus
- Login to Azure
- Click SERVICE BUS and Choose +NEW
- NAMESPACE NAME: MySignalR
- REGION: West US
- Click the Checkmark
- Click the newly created namespace
- Click Connection Strings from Below
- Copy the connection string, you'll use it in your Web Project
Step 3 : Setup Visual Studio 2013 Solutions
- Open Visual Studio 2013 as Administrator
- File > New Project
- Click Installed > Templates > Visual C# > Cloud
- Click Windows Azure Cloud Service
- Enter the following values:
- Name: MySignalR.Cloud.Service
- Solution Name: MySignalR
- Click OK
- In the ".NET Framework 4.5 roles" column, choose "ASP.NET Web Role" and click [>]
- In the right column of Windows Azure Cloud Service Solution, Click on WebRole1 and then click the pencil to edit.
- Change the name to MySignalR.Web and click the empty space beneath.
- Click OK
- New ASP.NET Project - MySignalR.Web
- Choose MVC
- Choose Add unit tests
- Click OK
- Then the instructions on ASP.NET tell you to install SignalR
-
Install-Package -ProjectName SignalRChat Microsoft.AspNet.SignalR
Install-Package -ProjectName SignalRChat Microsoft.AspNet.SignalR.ServiceBus
- Set the backplane for Azure
- Update Web.Config so the connection string can be stored there.
<connectionStrings>
<add name="AzureServiceBus" connectionString="Endpoint=sb://xxxx.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=XXXXXXXX" />
</connectionStrings>
-
Startup.cs
public void Configuration(IAppBuilder app)
{
// Any connection or hub wire up and configuration should go here
string connectionString = ConfigurationManager.ConnectionStrings["AzureServiceBus"].ConnectionString;
GlobalHost.DependencyResolver.UseServiceBus(connectionString, "Chat");
app.MapSignalR();
}
- Update the MySignalR.Cloud.Service files
-
Open ServiceConfiguration.Cloud.cscfg and add a line for Microsoft.ServiceBus.ConnectionString with the value defined in the service bus dashboard.
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="MySignalR.Cloud.Service" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2014-01.2.3">
<Role name="MySignalR.Web">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.ServiceBus.ConnectionString" value="Endpoint=sb://xxxx.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=XXXXXXXX" />
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName={AccountName};AccountKey={AccountKey}" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
Right click the the MySignalR.Service.Cloud project and click Publish