一:
通过Nuget下载安装Microsoft.AspNet.SignalR(v2.1.1),注: 这个版本的Framework版本是:V4.5
二:
配置service端:
1 using System; 2 using System.Threading.Tasks; 3 using Microsoft.Owin; 4 using Owin; 5 using Microsoft.AspNet.SignalR; 6 using Newtonsoft.Json; 7 using Microsoft.AspNet.SignalR.Hubs; 8 9 [assembly: OwinStartup(typeof(Demo.Chat.MyStartup))]10 namespace Demo.Chat11 {12 public class MyStartup13 {14 public void Configuration(IAppBuilder app)15 {16 app.MapSignalR();17 }18 19 20 }21 [HubName("MyChat")]22 public class MyChat : Hub23 {24 public void Send(ShapeModel clientModel)25 {26 Clients.AllExcept(clientModel.LastUpdatedBy).sendMessage(clientModel);27 28 }29 30 31 }32 33 public class ShapeModel34 {35 [JsonProperty("content")]36 public string content { get; set; }37 [JsonProperty("name")]38 public string name { get; set; }39 [JsonIgnore]40 public string LastUpdatedBy { get; set; }41 }42 43 }
配置client:
我的通讯
运行效果: