Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I consider using SignalR over WCF duplex services?

I'm working on this project where there's a website that gets feeded data in "real time" through a wcf duplex service on a remote server. The updates have a frequency of about a second, and I use SignalR client side to update the view. (Every time there's an incoming 'packet' from the service, I notify my clients).

Currently I'm experiencing some issues with this solution because of the way the duplex service is working. Whenever there's no "real time" connection to the backend server feeding it with data, the service should just push the latest database-entry to my client. That works, but my clients view does not seem to pick up this properly. If I try to refresh the view, it's actually random what values are updated from time to time. (When debugging, the values are all there in the notify-methods)

I've tried using jquery / ajax to call a method in my controller setting up the connections like this:

setTimeout(function() {

        $.ajax({
            type: 'GET',
            url: '@Url.Action("ConnectToDataSources", "Fleet")', 
            cache: false,
            success: function (result) {

            }
        });
}, 1000)

And in my controller:

public void ConnectToDataSources()
{
    UnitContract[] listOfUnitsFromService = UnitClient.GetUnits(false, "", false);

    Model = new FleetModel
    {
        UnitDetails = GenerateUnitDetails(listOfUnitsFromService.ToList()),
    };

    foreach (UnitDetailsModel unit in Model.UnitDetails)
    {
        var ods = new OperationDataSource();
        var ads = new ActivityStatusDataSource();

        ads.Start(unit.UnitId, ActivityReceived, AliveReceived);
        ods.Start(DataReceived, unit.UnitId);
        _dataSources.Add(ods);
        _activityStatusDataSources.Add(ads);
    }
}

After a lot of trial and error I've considered changing the backend service to use SignalR as well. Have I understood it correctly that SignalR can actually replace the functionality I'm describing above on both server and client?

Also, if anyone has the same kind of setup I'm highly interested in hearing how you solved this issue :)

like image 202
Nicklas Pouey-Winger Avatar asked Jan 21 '14 08:01

Nicklas Pouey-Winger


1 Answers

Yes. SignalR uses WebSockets where it can and has fallbacks where it can't. WebSockets are much better than a duplex service because:

  1. It uses a single TCP connection to send data both ways.
  2. The server doesn't need to know the client's IP (it does in a duplex service, which doesn't work in a case of shared IP).

So.. yes. SignalR is a good fit.

like image 156
i3arnon Avatar answered Oct 09 '22 15:10

i3arnon