我正在尝试将一个小型WPF客户端应用程序连接到ASP.NET MVC 5服务中Windows Azure上托管的SignalR聊天应用程序。客户端在Web上运行良好,连接正常,但在使用WPF时,我不确定连接字符串需要通过服务总线。
的扩展版本他们使用:
string connectionString = "Endpoint=sb://xxxx.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=XXXXXXXX";
我在WPF客户端上尝试了很多不同的方法并且它起作用(Obviosley替换我自己的连接字符串):
public string Host = "Endpoint=sb://xxxx.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=XXXXXXXX";
Active = true;
Thread = new System.Threading.Thread(() =>
{
Connection = new HubConnection(Host);
Proxy = Connection.CreateHubProxy("ChatHub");
//Proxy.On("heartbeat", () => OnSendData("Recieved heartbeat"));
Proxy.On<ChatMessage>("Send", hello => OnSendData("Recieved send " + hello.Username + " " + hello.Content));
Connection.Start();
if (Connection.State == Microsoft.AspNet.SignalR.Client.ConnectionState.Connected)
{ MessageBox.Show("Connected!"); }
else
{
MessageBox.Show("Fail!");
}
while (Active)
{
System.Threading.Thread.Sleep(10);
}
}) { IsBackground = true };
Thread.Start();