CPA February 2016

Using SignalR with Azure Service Fabric

Is it possible to use signalR with Service Fabric provided by Microsoft? I'm trying to connect an UWP app and an angularJS app to my stateless reliable service hosted in an Azure Cluster through signalR/websocket connection. But both are not able to open such a connection. On my local machine everything works fine.

Is there anything special to consider of using signalR/websockets with Service Fabric? Is there any example?

Answers


Binu Vijayan March 2016

You need to enable cross-domain setting for signalR to call it from other applications.

 appBuilder.Map("/signalr", map =>
        {

            map.UseCors(CorsOptions.AllowAll);
            var hubConfiguration = new HubConfiguration()
            {
                EnableJSONP = true,
                EnableDetailedErrors = true,
                EnableJavaScriptProxies  = true
            };

            map.RunSignalR(hubConfiguration);
        });

This code can be found in the readme.txt file we get after installing the Nuget package for the SignalR. For cross domain feature, you need to install the Cores nuget package also.

After deploying this application, you can see that some calls to signalR fails and Some succeeds. By default the instance count in Reliable stateless service is -1. Thus multiple instances will be created for the service.

From signaleR Connection.Start() method three SingalR APIs will be called. These calls should happen within the same session in-order to work it properly. When we call these three API in Service Fabric with multiple instances, the call might be processed in different nodes and thus different sessions which leads to failure in singalR connection.

One solution is to Make the instance count 1 for the stateless service fabric application. I don't think that this is an elegant solution.

Post Status

Asked in February 2016
Viewed 3,411 times
Voted 10
Answered 1 times

Search




Leave an answer