2
votes

I am trying to use signalR for the first time however when my hub 'simpleEvent' is always undefined

$(document).ready(function () {

var simple = $.connection.simpleEvent;

....

If I go to localhost/mywebapp/signalR/hubs I get the following error message: "unable to download hubs from localhost. Unable to open this Internet site. The requested site is either unavailable or cannot be found.". However if I try again then hubs in downloaded and it looks like it has the correct hub information, such as

// Create hub signalR instance
$.extend(signalR, {
    simpleEvent: {
        _: {
            hubName: 'MyCorp.Siep.App.Web.UI.SimpleEventHub',
            ignoreMembers: ['init', 'timerExpired', 'namespace', 'ignoreMembers', 'callbacks'],
            connection: function () { return signalR.hub; }
        },

        init: function (callback) {
            return serverCall(this, "Init", $.makeArray(arguments));
        },

        timerExpired: function (state, callback) {
            return serverCall(this, "TimerExpired", $.makeArray(arguments));
        }
    }
});

signalR.hub = signalR("/App.Web.UI/signalr")
    .starting(function () {
        updateClientMembers(signalR);
    })
    .sending(function () {
        var localHubs = [];

        $.each(hubs, function (key) {
            var methods = [];

            $.each(this, function (key) {
                if (key === "obj") {
                    return true;
                }

                methods.push(key);
            });

            localHubs.push({ name: key, methods: methods });
        });

        this.data = window.JSON.stringify(localHubs);
    })
    .received(function (result) {
        var callbackId, cb;
        if (result) {
            if (!result.Id) {
                executeCallback(result.Hub, result.Method, result.Args, result.State);
            } else {
                callbackId = result.Id.toString();
                cb = callbacks[callbackId];
                if (cb) {
                    callbacks[callbackId] = null;
                    delete callbacks[callbackId];
                    cb.callback.call(cb.scope, result);
                }
            }
        }
    });

I have tried the SignalR samples and they work fine, I have read lots of other forum posts regarding this error and most of them appear to be because is incorrect, I am assuming that if I can download the hubs then this is not the issue. What else could be causing this problem?

I am trying to use signalR within: - A Web Appplication - Running within visual studio 2010 deployment server and iis 7 - Intenert Explorer 8 - Windows 2008 server

Any help would be greatly appreciated.

2

2 Answers

0
votes

Check you master page whether you have put correct script references

<script src="../Scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script src="../Scripts/jquery.signalR.js" type="text/javascript"></script>
<script src="../signalr/hubs" type="text/javascript"></script>
0
votes

The following files are important (check right order):

  1. jQuery JS File
  2. SignalR JS File
  3. HubFile Optinal if you're working with generated hubs.

Here is a sample:

<script src="Scripts/jquery-1.10.2.min.js"></script>
<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>
<script src="signalr/hubs"></script>

Check if the referenced files are in the directory (Maybe you have a console error that a referenced file is missing.

If you are working with generated hub proxy, it is important that you did not disabled the automatic generating of the hubproxy files (also path must be right)

var hubConfiguration = new HubConfiguration();
hubConfiguration.EnableDetailedErrors = true;
hubConfiguration.EnableJavaScriptProxies = false;
app.MapSignalR("/signalr", hubConfiguration);