Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Host SignalR in IIS

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);
        }
    }
like image 413
bRaNdOn Avatar asked Oct 17 '14 05:10

bRaNdOn


People also ask

Does SignalR require IIS?

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.

Where can I host a SignalR?

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).

Can SignalR be used in Web API?

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.


2 Answers

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

like image 71
Tim B James Avatar answered Oct 20 '22 00:10

Tim B James


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.

like image 43
Squirrelkiller Avatar answered Oct 19 '22 23:10

Squirrelkiller