'How can we implement Windows desktop application integrate with SignalR based on ASP.NET Boilerplate?
Our base project implemented with ASP.NET Boilerplate, ASP.NET MVC, AngularJS. We have desktop application that communicate with Web API project. How we can use SignalR in our desktop application?
Solution 1:[1]
In windows desktop framework 4.8 add Microsoft.AspNetCore.Http.Connections.Client from NuGet.
Create a Hub connection method
Map receive event hubConnection.On
Start with StartAsync()
HubConnection hubConnection;
string _messageRecived;
async Task InizializzaConnectioTuBlazorHub()
{
hubConnection = new HubConnectionBuilder()
.WithUrl("http://localhost:5000/chathub")
.Build();
hubConnection.On<string>("ReceiveMessage", (message) =>
{
_messageRecived = message;
textBox1.Text= _messageRecived;
});
await hubConnection.StartAsync();
}
After that, send a message.
async Task Send()
{
if (hubConnection != null)
{
await hubConnection.SendAsync("SendMessage", "Desktop: Ciao");
}
}
See Blazor Communicates with Win Desktop App through SignalR in the link I'v made a tips to communicate between Blazor and Windows form.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Giuseppe Pistorino |
