Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR with ASP.NET MVC and WinForms

I have an ASP.NET MVC application that includes functions invoked via SignalR. The ASP.NET application works fine and the data is updated for all clients in real time.

Can I create a WinForms application and connect to the same SignalR application and push data to my web applications through it? If so how can I connect to my SignalR Asp.NET MVC application through WinForms.

like image 592
progrAmmar Avatar asked Apr 14 '16 08:04

progrAmmar


1 Answers

Sure! You can use the SignalR client to connect to the server running inside your ASP.NET application.

Check this for a full sample with a Console application (but it's the same for Winforms).

You need to use Microsoft.AspNet.SignalR.Client.Hubs than you can create a connection like this:

    var hubConnection = new HubConnection("http://localhost:53748");
    var chat = hubConnection.CreateHubProxy("ChatHub");

    chat.On<string, string>("broadcastMessage", (name, message) => { Console.Write(name + ": "); Console.WriteLine(message); });

    hubConnection.Start().Wait();
    chat.Invoke("Notify", "Console app", hubConnection.ConnectionId);
like image 186
Luca Ghersi Avatar answered Oct 01 '22 03:10

Luca Ghersi