Chris
Chris

Reputation: 7601

SignalR - cross application use

I have a WPF app which is going to be deployed to multiple users on a LAN. The users of this app will be factory workers in a manufacturing company, who will be using the app to update their progress on each order.

The customer also has an ASP.NET webforms app which is used for entering orders among other things. What I want to build in this ASP.NET app is a screen that will give live updates of the progress of the factory workers. I've been looking at SignalR for this, but I'm unsure about whether it'll let me send updates from a separate application (I.e WPF to the WebForms app). Is this possible? If so are there any examples of cross application SignalR use online?

Thanks!

Upvotes: 2

Views: 450

Answers (2)

Hallvar Helleseth
Hallvar Helleseth

Reputation: 1867

If both the WPF and WebForms apps connect to the same server then this is simple to implement.

Setup a SignalR Hub:

public class ProgressHub : Hub {

}

When loading the WebForms app load/show the current progress in an ordinary manner. Setup SignalR to get live updates to the progress:

var appHubProxy = $.connection.appHub;
appHubProxy.client.progress = function (orderId, percent) {
    console.log(orderId + ': ' + percent);
};
$.connection.hub.start()

The WPF app calls the server to update the progress (using e.g WebAPI), in this handler call the signalr clients progress method:

public class ProgressController : ApiController {
    public void Post(string orderId, int percent) {
        // <Save progress to DB, etc>

        // Get instance of the SignalR ProgressHub context
        var hubContext = GlobalHost.ConnectionManager.GetHubContext<ProgressHub>();

        // Invoke the progress method on all connected clients.
        // You probably want to use Groups to only send customers
        // events for its own orders
        hubContext.Clients.All.progress(orderId, percent);  
    }
}

Or you could have WPF use the .NET SignalR API to call a method in the Hub instead:

public class ProgressHub : Hub {
    public void Progress(string orderId, int percent) {
        // <Save progress to DB, etc>

        // Invoke the progress method on all connected clients.
        // You probably want to use Groups to only send customers
        // events for its own orders
        Clients.All.progress(orderId, percent);  
    }
}

Upvotes: 1

Will Dean
Will Dean

Reputation: 39500

There is a SignalR client which is part of the standard set of SignalR bits that lets you build signalr support straight into .net desktop apps.

See http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-net-client

You can use this in combination with JavaScript web-page clients without problem.

Upvotes: 1

Related Questions