Asked by:
SignalR chat example don't work after rename of method

Question
-
User985539871 posted
Hello,
I use example code from https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server#comments-container. After change I name of method Send to new name SendToNetApp, sending messages don't work. If use I net as new name of method Send, messaging works normally. Are limits for methods names?
Friday, February 10, 2017 3:28 PM
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,
DillionSaturday, April 1, 2017 6:38 AM