locked
How to host a singlaR web app under IIS? is it possible? RRS feed

  • Question

  • User-1651604128 posted

    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?

    If it is possible, I want this signalR server to send notification when it is started. I mean the signalR server will not be triggered by client, it will send the notification automatically.

    This is the console example from internet, but I donot want the console app, I want a signalR works as web server, a web application.

     

    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);
            }
        }

    Thursday, January 28, 2016 2:08 AM

All replies

  • User753101303 posted

    Hi,

    You should easily find this at http://www.asp.net/signalrbut but your final goal is unclear. The connection needs to be established firs (ie you point a browser to a page on the server)). And then the server can send messages to the client side web page without having the client requesting for them.

    Here it sounds like you would like the server to send a message to clients without ever having heard about them? Try perhaps to explain the final non technical goal.

    For example, if this is to notify someone that a server started, sending a mail message or having a Dashboard hosted on a 3rd party server and on which the user will point his browser all day seems better.

    Thursday, January 28, 2016 8:00 AM
  • User-1651604128 posted

    Hi,

    You should easily find this at http://www.asp.net/signalrbut but your final goal is unclear. The connection needs to be established firs (ie you point a browser to a page on the server)). And then the server can send messages to the client side web page without having the client requesting for them.

    Here it sounds like you would like the server to send a message to clients without ever having heard about them? Try perhaps to explain the final non technical goal.

    For example, if this is to notify someone that a server started, sending a mail message or having a Dashboard hosted on a 3rd party server and on which the user will point his browser all day seems better.

    Hi PatriceSc, Thanks for your quick response, and sorry for the confusing...

    Yes, all I want is to create a SinalR server works as a web server and send some updated data to web client without client request. Basically, if there is a updates from SQL database table, the SignalR server will do something and then send the updates to client.

    I searched a lot from internet, I can see many posts related to SignalR Self Host, for example, this one http://sonyarouje.com/2012/10/02/signalr-real-time-pushing-of-data-to-connected-clients/

    but all of them are built on ASP.net console app, I do not want a console app, I need to build it as a web server.

    Please let me know if you have any further question, thanks a lot for your help,

     

    Thursday, January 28, 2016 3:49 PM
  • Thursday, January 28, 2016 4:03 PM
  • User-1651604128 posted

    Hi PatriceSc,

    Thanks a lot for your URL, actually, I saw this tutorial. it is not what I am looking for.

    That chat signalR is triggered by the button on client side to create the communication. what I want is to initiate the communication from SignalR hub server side, 

    There is not client side event required. 

    Anyway, thank you... 

    Thursday, January 28, 2016 10:34 PM
  • User753101303 posted

    More precisely it shows what you need to do to host a SignalR application iin IIS which is your first issue. Then it shows not only how to send messages to the server but also how to listen to what the server sends (ie the purpose is to send messages on one machine, this message is sent to the server and the server then send it to all clients). Of course the idea is to adapt this code. AFAIK you'll keep starting the connection and receiving messages even if you don't need the sending part.

    And so the hub class would listen to db changes (SqlDependency likely) to send then i to the client. I never done this but I believe it should work.

    Make sure listening to db changes is your best option. To me it is interesting if changes are done by a 3rd party app. If done by your own app, it's likely simpler to just intercept those changes when they are written to the db.

    It was not meant to provide something that would do exactly what you want but imo it does provide what you need on the SignalR side. Start maybe and then tell where you are stuck.

    Ah or by searching on both keywords I found http://techbrij.com/database-change-notifications-asp-net-signalr-sqldependency

    Friday, January 29, 2016 12:04 AM
  • User-1651604128 posted

    More precisely it shows what you need to do to host a SignalR application iin IIS which is your first issue. Then it shows not only how to send messages to the server but also how to listen to what the server sends (ie the purpose is to send messages on one machine, this message is sent to the server and the server then send it to all clients). Of course the idea is to adapt this code. AFAIK you'll keep starting the connection and receiving messages even if you don't need the sending part.

    And so the hub class would listen to db changes (SqlDependency likely) to send then i to the client. I never done this but I believe it should work.

    Make sure listening to db changes is your best option. To me it is interesting if changes are done by a 3rd party app. If done by your own app, it's likely simpler to just intercept those changes when they are written to the db.

    It was not meant to provide something that would do exactly what you want but imo it does provide what you need on the SignalR side. Start maybe and then tell where you are stuck.

    Ah or by searching on both keywords I found http://techbrij.com/database-change-notifications-asp-net-signalr-sqldependency

    Hi PatriceSc, thanks a lot again...

    I think there should be a way to do it, just can not find it so far, but I do find some examples of Console apps, which is not working on web.

    I saw the example you posted, two things, 1. it is used for SQL server database, but in my case, my database is DB2 db. 2. It needs to run the service broker in  order to make it work. I do not know if my DBA allows me to do it if it is a SQL server db.

     

    Any way, thanks again

    Friday, January 29, 2016 6:19 PM