I'm just wondering and it is hunting me for these past few days is it possible to Host a SignalR Hub in IIS? is that event possible? i found a solution called "self hosting" but it is with the help of a console application. i want to host the SignalR Hub in my IIS is that possible? can someone provide me an example regarding this?
im going to post the code for the self Hosting i thought i might help
class Program
{
static void Main(string[] args)
{
// This will *ONLY* bind to localhost, if you want to bind to all addresses
// use http://*:8080 to bind to all addresses.
// See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx
// for more information.
string url = "http://localhost:8080";
using (WebApp.Start(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
}
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
public class MyHub : Hub
{
public void Send(string name, string message)
{
Clients.All.addMessage(name, message);
}
}
Supported server IIS versions Also note that for SignalR to use WebSocket, IIS 8 or IIS 8 Express must be used, the server must be using Windows 8, Windows Server 2012, or later, and WebSocket must be enabled in IIS.
A SignalR server is usually hosted in an ASP.NET application in IIS, but it can also be self-hosted (such as in a console application or Windows service) using the self-host library. This library, like all of SignalR 2, is built on OWIN (Open Web Interface for . NET).
SignalR can be used together with Web API just fine, so some functionality in application which is not realtime and doesn't require persistent connection could be served by Web API.
Hosting SignalR in IIS is as simple as creating a website with a SignalR Hub, and then publishing it to a website within your IIS.
The SignalR Hub will then be located at http://www.yourdomain.com/
If you follow this tutorial here, you will find out what you need http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr
Websocket support is not enabled by default on IIS. It was introduced in IIS 8, and has to be enabled from windows' optional features: https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support
Optional features -> IIS -> WWW services -> App Dev Features -> Websocket protocol
Disclaimer: I found this after asking a question about this myself, so I copied my answer from there: https://stackoverflow.com/a/61411666/4364057
In case somebody finds this after me, I'd like to provide a working answer to the question that I think is better than the accepted one.
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