locked
SignalR, MVC Web App, Web Api & Knockout.js RRS feed

  • Question

  • User-331009151 posted

    Hi all, I am going around in circles here and cannot find any tutorials or examples that meet my needs. I have an existing web application written in c# based on MVC, knockout.js and a RESTful Web Api that handles all of the back end service. I need to be able to include SignalR to update the UI from the Web Api in real time for a booking system. Can anyone point me to any examples of such a set up? Both the Web App UI and Web Api are on separate URL's but do reside on the same server. All the examples and tutorials I can find only seem to include both the Web App and Web Api inside the same single project whereas I have 2 separate projects. I posted a similar question here last week but did not get much in the way of a response so any help greatly appreciated.

    Thursday, March 31, 2016 3:23 PM

Answers

  • User61956409 posted

    Hi scout7,

    Do you have OWIN Startup Class? You could add a plain Class called Startup instead, and change the contents of the new Startup class to the following.

    using Microsoft.Owin;
    using Owin;
    [assembly: OwinStartup(typeof(SignalRChat.Startup))]
    namespace SignalRChat
    {
        public class Startup
        {
            public void Configuration(IAppBuilder app)
            {
                // Any connection or hub wire up and configuration should go here
                app.MapSignalR();
            }
        }
    }
    

    Besides, this link discussed a similar issue, you could refer to it.

    http://stackoverflow.com/questions/20068075/owin-startup-class-missing

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2016 8:17 AM

All replies

  • User61956409 posted

    Hi scout7,

    You could try to use the following code to broadcast message to clients from controller action.

    var hubContext = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
    hubContext.Clients.All.broadCastMessage("your message");
    

    Besides, it could be difficult for searching some samples that could meet all of your requirements, you had better to learn the basic usage of ASP.NET SignalR.

    http://www.asp.net/signalr

    Best Regards,

    Fei Han

    Friday, April 1, 2016 7:21 AM
  • User-331009151 posted

    Thank you for your reply, I am just missing that light-bulb moment! As a very basic setup if I could find a very basic cross domain web app / web api example where the web api pushes in real time would be great. I am going around in circles. Here is an example of where I have got to so far;

    I have created a solution called 'SignalR.Solution' that contains to 2 projects called 'SignalR.Api' (which is an MVC API project with its own URL and app pool in IIS) and 'SignalR.Web' (which is an MVC web App project with its own URL and app pool in IIS).

    I have installed the signalr packages in both projects. I have also installed the owin package in the api.

    I have created an OWIn startup class in my api project.

    From my client I am trying to access the api signalr as follows <script src="http://local.signalr.api.com/signalr/hubs"></script>

    and a function with this '.connection.hub.url = 'http://local.signalr.api.com/signalr';'

    As a basic test I try to run this and get the following errors;

    The following errors occurred while attempting to load the app.
    - No assembly found containing an OwinStartupAttribute.
    - No assembly found containing a Startup or [AssemblyName].Startup class.
    To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
    To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

    I know there is a lioghtbulb moment that I am missing here but I am getting very frustrated so if anybody can help save my sanity I would greatly appreciate it!

    Friday, April 1, 2016 1:35 PM
  • User61956409 posted

    Hi scout7,

    Do you have OWIN Startup Class? You could add a plain Class called Startup instead, and change the contents of the new Startup class to the following.

    using Microsoft.Owin;
    using Owin;
    [assembly: OwinStartup(typeof(SignalRChat.Startup))]
    namespace SignalRChat
    {
        public class Startup
        {
            public void Configuration(IAppBuilder app)
            {
                // Any connection or hub wire up and configuration should go here
                app.MapSignalR();
            }
        }
    }
    

    Besides, this link discussed a similar issue, you could refer to it.

    http://stackoverflow.com/questions/20068075/owin-startup-class-missing

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2016 8:17 AM