Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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")

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 IIS
++++++++++++++++++++++++++++++++++++++++++++++++

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 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 ?

What I have tried:

I have spent days researching this, gone down many rabbit holes but still do not have an answer
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900