locked
SignalR for WCF Service running in IIS RRS feed

  • Question

  • User-587269734 posted

    Help please !!!

    I am relatively new to asp.net and  have spent the past 3 days trying to get a simple version of signalR  configured in my C# WCF service. But I seem to be going around in circles. The first problem is confusion about where the different elements or signalR need to be loaded/created. Maybe it is best for me to give my understanding of the required setup.

    My setup is as follows:

    • My Service application is a C# WCF service which runs in IIS8  on a windows 2012R2 server.  ("The Service")
    • My Client application is a C# WebForm application running on the same windows 2012R2 server ("The Client")
    • The Client application has a JavaScript file called myJavaScript.js ("The JavaScript File")
    • Users access the service via the "CLIENT" running on a web browser, usually Chrome ("The Browser") 
    • Failed to load resource: the server responded with a status of 404 (Not Found)

    Below are the changes that I have made to "The Service", "The Client" & "The JavaScript file" in my attempts to send a simple message from the Service to the Browser via signalR. 

    Changes to "The Service" (application name DCRules2)

    • Downloaded from nuget Microsoft.AspNet.SignalR  v2.2.2
    • Downloaded from nuget Microsoft.AspNet.SignalR,Core  v2.2.2
    • Downloaded from nuget Microsoft.AspNet.SignalRJS  v2.2.2
    • Downloaded from nuget Microsoft.AspNet.SignalR.SystemWeb  v2.2.2
    • Downloaded from nuget Microsoft.Owin.SystemWeb  v3.1.0
    • Downloaded from nuget Microsoft.Owin   v3.1.0
    • Downloaded from nuget Microsoft.Owin.Security   v3.1.0
    • Downloaded from nuget Owin   v1.0.0

    Added an Owin Startup Class Startup1.cs

    using System;
    using System.Threading.Tasks;
    using Microsoft.AspNet.SignalR;
    using Microsoft.Owin;
    using Owin;
    using DCRules2;
    [assembly: OwinStartup(typeof(DCRules2.Startup1))]
    
    namespace DCRules2
    {
        public class Startup1
    
        {
            public void Configuration(IAppBuilder app)
    
            {
                // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
    
                 //app.MapSignalR();
    
                 //app.MapSignalR("/~/signalr", new HubConfiguration());         
    
                 var hubConfiguration = new HubConfiguration();
    
                 app.MapSignalR("/signalr", hubConfiguration);
            }
        }
    }



    Added Hub class TiosHub.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Microsoft.AspNet.SignalR;
    using Microsoft.AspNet.SignalR.Hubs;
     
    
    namespace DCRules2
    {
        //[HubName("tios")]
        public class TiosHub : Hub
        {
            // Tell all of the clients that there is an announcement
            public void Announce(string message)
            {
                Clients.All.Announce(message);
            }
        }
    }

    Rebuilt the service and restarted IIS8

    ++++++++++++++++++++++++++++++++++++++++++++++++

    Changes to "The Client" (application name DCRulesWeb01)

    • Downloaded from nuget Microsoft.AspNet.SignalR.Client  v2.2.2
    • Downloaded from nuget Microsoft.Owin.SystemWeb  v3.1.0
    • Downloaded from nuget Microsoft.Owin   v3.1.0
    • Downloaded from nuget Owin   v1.0.0

    I added the javascript references to Webform1.aspx

    <script src="~/Scripts/jquery.signalR-2.2.2.js">
    </script> <script src="~/signalr/hubs"></script>

    I added an announce() method to Webform1.aspx.cs  to test signalR

     

           // Test SignalR
            public void Announce(string message)
            {
                string msg = message;
            }

    ++++++++++++++++++++++++++++++++++++++++++++++++

    Changes to "The JavaScript file" (application name DCRulesWeb01)

    File myJavaScript.js is a clientside javascript file which I inserted the following code into:

    // SignalR configuration
    
    $(function () {
        var tioshub = $.connection.tiosHub;
        $.connection.hub.start().done(function () { });
        tioshub.client.announce = function (message) {
        console.info('Received message: ' +message);
        }
    });

    finally I re-built the Client application and published the Project and re-started IIS

    When I run the service and press F12 , I get the following errors

    1. Failed to Load resource - the server responded with a status of 404 (not found)       jquery.signalR-2.2.2.js
    2. Failed to Load resource - the server responded with a status of 404 (not found)       hubs
    3. Uncaught TypeError: Cannot read property 'tiosHub' of undefined

     

    One thing I had expected to see was the creation of a folder signalr/hubs  which has not happened. I am assuming that this is related to 404 error above.

    Can anyone explain what I might be doing wrong ? 

    Tuesday, October 3, 2017 7:00 PM

All replies

  • User-335504541 posted

    Hi pclarkeirl,

    Please try to change

    <script src="~/signalr/hubs"></script>

    to

    <script src="/signalr/hubs"></script>

    Best Regards,

    Billy

    Thursday, October 5, 2017 12:06 PM
  • User-587269734 posted

    Hi Billy,

    thanks for getting back to me. Just tried that but same result HTTP 404. Do you think I have everything in the right place or am I mixing up setup between Server & Client ?

    regards

    Pat

    Thursday, October 5, 2017 12:20 PM
  • User-335504541 posted

    Hi pclarkeirl,

    Have you added SignalR.AspNet.dll in your client side?

    You could refer to the link below for more information:

    https://stackoverflow.com/questions/8941595/signalr-signalr-hubs-giving-404-error

    Best Regards,

    Billy

    Monday, October 9, 2017 2:17 AM