I already know from asking here that I can have SignalR in a plain old Windows Service. I want to communicate between that Windows Service as a SignalR Client and a ASP.NET MVC SignalR Server. I used this hubs guide, It said
Server code that specifies the URL
app.MapSignalR("/signalr", new HubConfiguration());
If I do that, where will the messages go? What is the hub when you do new HubConfiguration?
It says I can connect with
NET client code that specifies the URL
var hubConnection = new HubConnection("http://contoso.com/signalr", useDefaultUrl: false);
I'll have that in my Windows Server but if I send text to http://myserver.com/signalr on the server, how do I get it? What hub?
Also where best to put this in the Windows service? An example would be great!
There is a library called SignalR, which is included in ASP.NET Core. SignalR doesn't only enable you to achieve real-time two-way communication between applications. It also substantially simplifies the process of enabling all of this in the code.
Windows Desktop and Silverlight Applications In addition to running in a web browser, SignalR can be hosted in standalone Windows client or Silverlight applications.
The answer is no, SignalR is not backwards kompatible.
IIS on client operating systems has a limit of 10 concurrent connections. SignalR's connections are: Transient and frequently re-established. Not disposed immediately when no longer used.
This solves the problem
On the client (Windows Service):
protected override async void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart");
try
{
var hubConnection = new HubConnection("http://www.savitassa.com/signalr", useDefaultUrl: false);
IHubProxy alphaProxy = hubConnection.CreateHubProxy("AlphaHub");
await hubConnection.Start();
await alphaProxy.Invoke("Hello", "Message from Service");
}
catch (Exception ex)
{
eventLog1.WriteEntry(ex.Message);
}
}
On the server:
public class AlphaHub : Hub
{
public void Hello(string message)
{
// We got the string from the Windows Service
// using SignalR. Now need to send to the clients
Clients.All.addNewMessageToPage(message);
// Send message to Windows Service
}
I think I don't understand exactly what you want.
** Signal R. Server: Hosted as a Windows Service
** Signal R. Client: ASP.NET MVC Application.
** Signal R. Server: ASP.NET MVC Application.
** Signal R. Client: Windows Service
If what you need is Option A. You might want to take a look at "Signal R Self-Host Tutorial" If what you need is Option B. You need to create a .Net Signal R Client in the Windows Service. Please check out this tutorial on how to do so.
Regardless of your hosting type each hub has a unique name which you need to use when establishing the connection.
Regarding:
I'll have that in my Windows Server but if I send text to http://myserver.com/signalr on the server, how do I get it? What hub?
Signal R is an abstraction of realtime dual channel communication, so it really depends on the setup of your Hub.
Regarding:
Also where best to put this in the Windows service? An example would be great!
I would say, go simple and start by declaring a Singleton to start.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With