I'm struggling at connecting my C# code to an existing SignalR hub. This hub is created in SignalR 1.0
I have a pretty straight forward situation. The hub is defined as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR.Hubs;
namespace POC.SignalR.WebHost.Hubs
{
[HubName("SignalRHub")]
public class SignalRHub : Hub
{
/// <summary>
/// Joins the group.
/// </summary>
/// <param name="groupname">The groupname.</param>
public void JoinGroup(string groupname)
{
Groups.Add(Context.ConnectionId, groupname);
Clients.OthersInGroup(groupname).newMemberMessage(Context.ConnectionId);
Clients.Caller.JoinedGroup(groupname);
}
When I connect to the hub using Javascript it all works like a charm.
// Check if url exists and give it a default value if that's the case.
if (!url) { url = 'http://www.someurl.com/signalr'; }
conn = $.connection.SignalRHub;
var currentGroupName = '';
if (typeof groupName == "string") currentGroupName = groupName;
$.connection.hub.url = url;
$.connection.hub.logging = true;
// Start the connection
$.connection.hub.start().done(function () {
verbosemsg(conn.connection.state);
conn.server.connectionName();// init to get my connectioID
verbosemsg('Connection made now joining group:' + currentGroupName);
if (currentGroupName != '') conn.server.joinGroup(currentGroupName);
});
But when I connect to the hub in C# using the following code, I keep running into a "'JoinGroup' method could not be resolved." error. The hubConnection is in "connected" state and seems correct.
HubConnection hubConnection = new HubConnection("http://www.someurl.com/signalr", false);
IHubProxy hubProxy = hubConnection.CreateHubProxy("SignalRHub");
hubConnection.Start().Wait();
hubProxy.Invoke("JoinGroup", hubConnection.ConnectionId, "SignalRChatRoom").Wait();
As far as I can see I've implemented my code similar as found on this example: http://www.asp.net/signalr/overview/older-versions/signalr-1x-hubs-api-guide-net-client#establishconnection There must be something I've overlooked but I cannot figure it out. It would be great if someone can point me in the right direction.
Thx.
JoinGroup
method with two parameters while the methods on the server takes just on parameter - the group name. This should work:hubProxy.Invoke("JoinGroup", "SignalRChatRoom");
. Also you should not use.Wait()
butawait
otherwise you can have deadlocks. – Pawel