Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to signalr. I've got a chat application working but I'll like to pass in parameters in my methods. When I pass parameters in hub, I get detail error:

C#
at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.<>c__DisplayClass13.<OnReceived>b__10(IHub emptyHub, Object[] emptyParameters)
at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.Incoming(IHubIncomingInvokerContext context)

'Connect' method could not be resolved.`


here is my client code:

JavaScript
$("#btnStartChat").click(function () {
        var name = $("#txtNickName").val();
        var userEmail = $("#userEmail").val();
        if (name.length > 0 || userEmail.length > 0) {
            chatHub.server.connect(name, userEmail).fail(function (error) {
                console.log('Connect error: ' + error)
            });
        }
        else {
            alert("Please enter name and email.");
        }

    });


Here is my Hub method:

C#
public void Connect(string userName, string someEmail)
{
    var id = Context.ConnectionId;

    if (ConnectedUsers.Count(x => x.ConnectionId == id) == 0)
    {
        ConnectedUsers.Add(new UserDetail { ConnectionId = id, UserName = userName });

        // send to caller
        Clients.Caller.onConnected(id, userName, ConnectedUsers, CurrentMessage, someEmail);

        // send to all except caller client
        Clients.AllExcept(id).onNewUserConnected(id, userName);
    }

}


Calling all angels and guru dev saints for a healing. I've being suffering from problem for a week now! Thank you for your efforts.
Posted
Comments
ZurdoDev 1-Aug-13 12:25pm    
It is case sensitive. You are calling connect in client but C# has Connect.
[no name] 1-Aug-13 12:39pm    
Thanks for your effort! Din't work and also the Signalr API to call methods in the hub from the client is done in lower Camel-case. The method works well well with only one parameter, i.e "name" but when I add a second parameter "userEmail", it throws that error.
Maarten Kools 1-Aug-13 12:42pm    
Could this potentially be the issue? SignalR Error 500 when calling server from client in ASP.NET 4.5 Website[^] Unfortunately I've never done anything with SignalR (looks pretty interesting though! Bookmarked it)
[no name] 1-Aug-13 13:04pm    
No, it is not! The issue here is, Signalr server methods throw arrows at me for putting parameters in them.
Richard C Bishop 1-Aug-13 17:20pm    
I didn't know server methods could be booby-trapped.

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