1

I am new to both ASP.NET MVC and Signalr. I am following this tutorial to learn SQL interaction with ASP>NET via signalr.

I have tried below steps

  1. Created a new Project "ASP.NET MVC3"
  2. Selected Internet application with razor view engine.
  3. Installed Microsoft ASP.NET signalr via nuget
  4. Created the same database and same table.
  5. Modified my webconfig by adding the connectionstring.
  6. Applied Changes in the Global.asax to enable & stop listner.
  7. Added a class "JobInfo" - similar to step 5 in the link.
  8. On step 7 of the tutorial when I click on project > add new item , I didn't find Signalr hub class. So I added a normal class with the same name

Code

   namespace MvcApplication1
{
    public class JobHub
    {
        public static void Show()
        {
            IHubContext context = GlobalHost.ConnectionManager.GetHubContext<JobHub>();
            context.Clients.All.displayStatus();
        }
    }
}

Now, when I am building my solution I am getting this error

  The type 'MvcApplication1.JobHub' cannot be used as type parameter 'T' in the generic type or method 'Microsoft.AspNet.SignalR.Infrastructure.IConnectionManager.GetHubContext<T>()'. 
There is no implicit reference conversion from 'MvcApplication1.JobHub' to 'Microsoft.AspNet.SignalR.Hubs.IHub'.

Also, I am not sure how to implement step 8 because when I clicked on controller to add "valueController" I am not able to inherit it from "ApiController".

Below is the screen shot of my application.

How can I fix this? enter image description here

2
  • Perhaps try public class JobHub : IHub or something along those lines. It seems like you should be inheriting there. Commented Mar 20, 2013 at 19:26
  • it is giving me 'MvcApplication1.JobHub' does not implement interface member 'Microsoft.AspNet.SignalR.Hubs.IHub.Clients' Commented Mar 20, 2013 at 19:28

1 Answer 1

4

This is the part that you were missing I think. It seems that JobHub must inherit from Hub. Include this reference and then try to inherit from Hub.

using Microsoft.AspNet.SignalR.Hubs;

public class JobHub : Hub
{
    public static void Show()
    {
        IHubContext context = GlobalHost.ConnectionManager.GetHubContext<JobHub>();
        context.Clients.All.displayStatus();
    }
}

Step 8

@Zerotoinfinite - It would seem that using System.Web.Http; is required for the ApiController which is included in asp.net mvc 4. As such, you may want to start a project which is mvc 4, or, just use a regular controller which wont really be any different.

public class ValuesController : Controller
{

   JobInfoRepository objRepo = new JobInfoRepository();


   // GET api/values
   public JsonResult Get()
   {
       return Json(objRepo.GetData());
   }
}
Sign up to request clarification or add additional context in comments.

4 Comments

+1 This worked. Can you please also guide me about the 8th step (tutorial) I have mentioned in my question. "ValueController"
It should be just like in the tutorial. You may have to click on ApiController to resolve the issue as far as adding a using directive. The difference between a normal controller and an apicontroller is that ApiControllers are used for data retrieval only, and only return serialized data.
I tried that but it is not suggesting any namespace. :( Do I have to create it under controller folder or like a class?
To get the item template for the SignalR Hub class you need to install ASP.NET and Web Tools 2012.2 from asp.net/downloads

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.