locked
ASP .Net SignalR - proxy to reference the hub - what type of case-senstivity / insenstivity is being applied? RRS feed

  • Question

  • User-1319896600 posted

    Hi,

    I have class named MessagesHub that is derived from the Hub class, note the capital M in the MessagesHub.

    However, when I try to create a proxy to reference the hub in javascript, it fails if I use a capital M, but succeeds if I use a lowercase m

            var notifications = $.connection.MessagesHub; //FAILS         with uppercase M
            var notifications = $.connection.messagesHub; //SUCCEEDS with lowercase m

    Why does the capital MessagesHub reference fail in javascript?

    Thanks

    Thursday, July 2, 2015 7:24 PM

Answers

  • User1644755831 posted

    Hello,

    However, when I try to create a proxy to reference the hub in javascript, it fails if I use a capital M, but succeeds if I use a lowercase m

    Generally it seems that the first letter will always be lowercase. If you are having case sensitivity issue then try applying HubName Attribute to give it name explicitly.

    [HubName("stockTicker")]
    public class StockTickerHub : Hub

    the reference to the SignalR generated proxy is to dynamically generated JavaScript code, not to a physical file.  SignalR creates the JavaScript code for the proxy on the fly and serves it to the client in response to the "/signalr/hubs" URL.

    You could manually create a physical file for the SignalR generated proxy.

    Please see: http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client

    Hope this helps.

    With Regards,

    Krunal Parekh

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 5, 2015 10:48 PM
  • User71929859 posted

    ihaveaquestion

    Why does the capital MessagesHub reference fail in javascript?

    Because javascript will have references to the server hub class and the members of it by camelCase. We usually write javascript with camel case and C# in pascal case. If you want to use the name as it is, then decorate your hub class with HubName attribute. Like below

    [HubName("MessagesHub")]
    public class MessagesHub: Hub{

    }

    Now you can access your hub in javascript like below

    var notifications = $.connection.MessagesHub;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 6, 2015 2:05 AM

All replies

  • User1644755831 posted

    Hello,

    However, when I try to create a proxy to reference the hub in javascript, it fails if I use a capital M, but succeeds if I use a lowercase m

    Generally it seems that the first letter will always be lowercase. If you are having case sensitivity issue then try applying HubName Attribute to give it name explicitly.

    [HubName("stockTicker")]
    public class StockTickerHub : Hub

    the reference to the SignalR generated proxy is to dynamically generated JavaScript code, not to a physical file.  SignalR creates the JavaScript code for the proxy on the fly and serves it to the client in response to the "/signalr/hubs" URL.

    You could manually create a physical file for the SignalR generated proxy.

    Please see: http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client

    Hope this helps.

    With Regards,

    Krunal Parekh

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 5, 2015 10:48 PM
  • User71929859 posted

    ihaveaquestion

    Why does the capital MessagesHub reference fail in javascript?

    Because javascript will have references to the server hub class and the members of it by camelCase. We usually write javascript with camel case and C# in pascal case. If you want to use the name as it is, then decorate your hub class with HubName attribute. Like below

    [HubName("MessagesHub")]
    public class MessagesHub: Hub{

    }

    Now you can access your hub in javascript like below

    var notifications = $.connection.MessagesHub;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 6, 2015 2:05 AM
  • User-1319896600 posted

    Thanks

    Monday, July 6, 2015 10:32 AM