bdparrish
bdparrish

Reputation: 2774

SignalR - StartUp

I am looking for the quick and dirty answer. I am just blanking, and after staring at a screen for over 12 hours now, I think I am shot.

I want to do a simple SignalR application as a tutorial. I found this example, but I keep getting the error that tickets is undefined. I have found a couple more, and keep getting the same error. I compared the sample project to mine and I cannot find any descrepencies.

It seems as though $.connection.ticketHub or $.connection.chat are returning undefined objects. Is there something special that I need to do with /signalr/hubs? Any other thoughts are greatly appreciated.

Upvotes: 13

Views: 8821

Answers (5)

ren
ren

Reputation: 31

Lee Smiths answer was right on the money. I got the latest json2 from nuget and also make sure that you have the change in your web.config from the the signalR faq site:

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>

Upvotes: 3

Tom Stickel
Tom Stickel

Reputation: 20441

With Visual Studio 2010 / MVC 3 / Firefox Browser , my Index.cshtml is using SignalR just fine with the following

<script src="@Url.Content("~/Scripts/jquery-1.8.0.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.signalR-0.5.2.min.js")" type="text/javascript"></script>

<script src="/signalr/hubs" type="text/javascript"></script>

I had another issue, but I did not have to add in the @Url.Content to the signalr/hubs For simplicity on testing I also just have my class file in root of Controllers folder. I also have the following from Nuget

SignalR / SignalR.Js / SignalR.Server / SignalR.Hosting.AspNet / SignalR.Hosting.Common

(Not that you NEED all of those dependencies, but that is what I have)

Hope that helps someone...

Upvotes: 2

dhyabi
dhyabi

Reputation: 329

Change your script tag to this :

<script type="text/javascript" src='<%= ResolveClientUrl("~/signalr/hubs") %>'></script>

Upvotes: 2

Lee Smith
Lee Smith

Reputation: 6767

Are you using IE8?

If you are, make sure you include a Json2 script ref above the signalR script:

<script src="../../Scripts/json2.min.js" type="text/javascript"></script>

(Get Json2 from Nuget)

Upvotes: 3

MatteKarla
MatteKarla

Reputation: 2737

You need to add the /signalr/hubs to the page, it's a javascript dynamically generated by SignalR containing method stubs for your hubs and the methods on the hubs.

So if you have a .NET-hub named TestHub, with a method called SendMessage(string message) javascript will be generated so you can from JavaScript call: $.connection.testHub.sendMessage("some message to server");

Point your browser to the url: /signalr/hubs, and you should get a javascript.

about 150 lines down you will see the ticketHub stub:

$.extend(signalR, {
   ticketHub: {
      _: {
          hubName: 'YourNameSpace.TicketHub',
          ignoreMembers: ['someMethod', 'namespace', 'ignoreMembers', 'callbacks'],
          connection: function () { return signalR.hub; }
      },

You can use Mozilla Firebug plugin or Chrome developer tools (wrench-icon->Tools->Developer Tools) to see what's sent to and returned from server.

EDIT: There was a bug in SignalR preventing /signalr/hubs to be correctly generated (it didn't generate the method stubs). https://github.com/SignalR/SignalR/issues/134

EDIT2: you could have a incorrect script tag, try:

<script src="@Url.Content("~/signalr/hubs")" type="text/javascript"></script>

or you haven't referenced the SignalR.AspNet.dll assembly. If I recall correctly it's that assembly that wires up the route to /signalr.

Upvotes: 14

Related Questions