【问题标题】:SignalR:For Client Side,which signalR package,i need to install?SignalR:对于客户端,我需要安装哪个 signalR 包?
【发布时间】:2016-11-26 11:12:19
【问题描述】:

我是 SignalR 的新手。我正在使用 signalR 开发一个项目

服务端我使用 WCF 和 SignalR。对于客户端,我使用 ASP.NET MVC 4。

我按照以下网站中的步骤进行操作:-

Getting Started With SignalR and MVC 5

对于我的服务端,我安装了名为

的包

安装包 Microsoft.AspNet.SignalR

我还在 WCF 服务中创建了我的 owin 启动类和 SignalR Hub 类。

Owin StartupClass:-

 [assembly: OwinStartup(typeof(WCF3.Startup))]
 namespace WCF3
  {
    public class Startup
     {
        public void Configuration(IAppBuilder app)
         {
            app.MapSignalR();
         }
     }
  }

SignalR HubClass:-

     public class ConvHub : Hub
       {
         public void send(string user)
          {
              Clients.All.broadcastMesage(user);
          }
       }

和我的 WCF 服务:-

     public class Service1 : IService1
     {
         public string GetValue(string username)
         {
            string name = "username ="+username;
            Console.WriteLine("u=" + name);
            return name;
         }
     }

我的服务端配置已完成。

但我不知道,我需要为 ASP.NET MVC 安装哪个包,同时考虑 MVC 作为单独的客户端。

谁能告诉我包名,需要安装在MVC客户端吗?

【问题讨论】:

    标签: c# wcf asp.net-mvc-4 client signalr


    【解决方案1】:

    您需要将 Microsoft.AspNet.SignalR.Client 安装到您的 wcf 服务。

    在 wcf 服务中配置你的启动

     var connection = new HubConnection("{enter your hub url}");
     var myHub = connection.CreateHubProxy("ConvHub");
    
    
     myHub.Invoke("send", "your username").ContinueWith(task => {
                        if (task.IsFaulted)
                        {
                            Console.WriteLine("There was an error calling send: {0}", task.Exception.GetBaseException());
                        }
                        else
                        {
                            Console.WriteLine("Send Complete.");
                        }
                    });
    

    【讨论】:

    • 感谢 ahankendi 的评论。我会尽快检查并接受您的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多