locked
SignalR chat example don't work after rename of method RRS feed

All replies

  • User-1509636757 posted

    Are limits for methods names?

    You can name it as you need. However, you need to make sure that you use the same method name on client side code where you are sending messages, code might be similar like:

    var chat = $.connection.chatHub;
    ...
    ...
    chat.server.SendToNetApp($("#message").val());

    Friday, February 10, 2017 5:10 PM
  • User985539871 posted

    It has been observed, but the code does not work. With shorter name work it properly (tested with names "net" and "web").

    Friday, February 10, 2017 6:36 PM
  • User985539871 posted

    After many attempts, I found that the problem occurs when the name contains uppercase.

    Monday, February 13, 2017 1:14 PM
  • User-469665101 posted

    Hi,

    In SignalR, Always create method in "Camel-casing of method names"

    e.g :-

    C#
    public class ContosoChatHub : Hub
    {
        public void NewContosoChatMessage(string name, string message)
        {
            Clients.All.addNewMessageToPage(name, message);
        }
    }
    
    
    JavaScript client using generated proxy
    
    
    Copy
    
    html
    contosoChatHubProxy.client.addNewMessageToPage = function (name, message) {
        // Add the message to the page. 
        $('#discussion').append('<li><strong>' + htmlEncode(name)
            + '</strong>: ' + htmlEncode(message) + '<li>');
    };
    

    Tuesday, February 14, 2017 12:08 PM
  • User985539871 posted

    Lower-CamelCase? With the first character lowercase?

    Thursday, February 16, 2017 9:54 AM
  • User-271186128 posted

    Hi hlucheucho,

    Lower-CamelCase? With the first character lowercase?

    Yes, after you rename Send method to SendToNetApp in your hub class, please make sure that the first char of method name is lowercase when you call this method from your JavaScript client.

    chat.server.sendToNetApp(mes);

    Otherwise, it will return the error: Object doesn't support property or method 'SendToNetApp'.

    Best regards,
    Dillion

    Saturday, April 1, 2017 6:38 AM