Deployed SignalR app on Winhost.com and it's failing to instantiate the ChatHub chat object.

Discussion in 'General troubleshooting' started by robertjp, Feb 25, 2014.

  1. The application is a simple SignalR chat demo. It runs in a VS 2013 Express environment without any problems. Using .net 4.5, SignalR 2.0.2, and jQuery 2.1.0 (with updates applied).

    I've tried various suggestions on this forum and other sources on the Internet without any success.

    Has anyone successfully deployed a SignalR application using .Net 4.5? Any assistance or help will be greatly appreciated.

    -- Default.html --
    <!DOCTYPE html>
    <html>
    <head>
    <title>SlimSignalR</title>
    <style type="text/css">
    .container {
    background-color: #99CCFF;
    border: thick solid #808080;
    padding: 20px;
    margin: 20px;​
    }​
    </style>
    </head>
    <body>
    <div class="container">
    <input type="text" id="message" />
    <input type="button" id="sendmessage" value="Send" />
    <input type="hidden" id="displayname" />
    <ul id="discussion"></ul>
    </div>
    <!--Script references. -->
    <!--Reference the jQuery library. -->
    <script src="Scripts/jquery-2.1.0.min.js"></script>
    <!--Reference the SignalR library. -->
    <script src="Scripts/jquery.signalR-2.0.2.min.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="signalr/hubs"></script>
    <!--Add script to update the page and send messages.-->
    <script type="text/javascript">​
    $(function () {

    // Declare a proxy to reference the hub.
    var chat = $.connection.chatHub;
    alert("SignalR-ChatHub chat object is: " + chat);

    // Start the connection.
    $.connection.hub.start().done(function () {
    $('#sendmessage').click(function () {
    // Call the Send method on the hub.
    chat.server.send($('#displayname').val(), $('#message').val());
    // Clear text box and reset focus for next comment.
    $('#message').val('').focus();
    });​
    });

    // Create a function that the hub can call to broadcast messages.
    chat.client.broadcastMessage = function (name, message) {
    // Html encode display name and message.
    var encodedName = $('<div />').text(name).html();
    var encodedMsg = $('<div />').text(message).html();
    // Add the message to the page.
    $('#discussion').append('<li><strong>' + encodedName
    + '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>');
    };​

    // Get the user name and store it to prepend to messages.
    $('#displayname').val(prompt('Enter your name:', ''));
    // Set initial focus to message input box.
    $('#message').focus()

    });​
    </script>
    </body>
    </html>

    -- Startup.cs --
    using Microsoft.Owin;
    using Owin;
    using SlimSignalR;
    using System.Security;

    [assembly: OwinStartup(typeof(SlimSignalR.Startup))]

    namespace SlimSignalR
    {
    public class Startup
    {
    public void Configuration(IAppBuilder app)
    {
    // Any connection or hub wire up and configuration should go here
    app.MapSignalR();
    }​
    }​
    }

    -- ChatHub.cs --
    using System;
    using System.Web;
    using Microsoft.AspNet.SignalR;
    namespace SlimSignalR
    {
    public class ChatHub : Hub
    {
    public void Send(string name, string message)
    {
    // Call the broadcastMessage method to update clients.
    Clients.All.broadcastMessage(name, message);
    }
    }
    }

    -- web.config --
    <?xml version="1.0" encoding="utf-8"?>

    <!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    -->

    <configuration>
    <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <trust level="Full" />
    </system.web>
    <appSettings>
    <add key="owin:appStartup" value="SlimSignalR.Startup" />
    </appSettings>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
    </dependentAssembly>
    </assemblyBinding>
    </runtime>
    </configuration>
     
  2. SignalR apps run. From what I can see (reading your post as opposed to actually having the project in VS) your app should run. Where are you seeing an error? I mean if you load up the page, you click away from the alert, Im assuming the page does nothing, you then hit F12 and look at the console? What does it say exactly?

    Can you post a link to the page?
     
    Michael likes this.
  3. The 1st dialog box that appears after the page displays is showing if the ChatHub (Hub) is instantiated. In this case it displays "undefined". This dialog box is only to display the Hub object status.

    If it was properly instantiated, a 2nd dialog box would appear and request your name. After submitting it, you can enter text into the textbox hit the send button and that message/text will be send to other users logged in.

    Thanks.
     
  4. You had set /signalr directory as an application starting point via the control panel. I removed it for you. Your application works. SignalR is awesome, I wish you smooth sailing from here on in.
     
    ComputerMan and Michael like this.
  5. Chuck...Thank you!

    You're right---SignalR is is awesome! And, I'm looking forward in using it in my development.

    Again, thank you and the staff at Winhost!
     
    Last edited by a moderator: Oct 14, 2015
    ComputerMan and Michael like this.

Share This Page