Suppress proxy generation for some hubs or methods

后端 未结 3 423
渐次进展
渐次进展 2021-01-03 07:21

I\'m starting out with SignalR and I have a situation where I\'m going to have a SignalR site that will be broadcasting messages to clients, but I also need an admin interfa

3条回答
  •  [愿得一人]
    2021-01-03 07:39

    There is one trick using interfaces. As proxy will generate only public methods in proxy, you can create hub using interface like this:

    public class MyHub : Hub, IMyHub
    {
        void IMyHub.NotGeneratedOnClient()
        {
        }
    
        public void GeneratedOnClient()
        {
        }
    }
    

    NotGeneratedOnClient method will not be visible if you use object of type MyHub, you can access it only using interface. As method is not public proxy generator is not going to add it to client proxy

提交回复
热议问题