C# WP8中signar的使用
我有一个WindowsPhone8客户端 我正在使用信号器与我的服务器通信 我需要我的用户界面更新来自我的服务器的消息 我知道服务器部分是正确的,因为我设置了断点并使用了HTML5客户端 问题在于WP8 我以前从未使用过WP8,所以我不确定我是否正确使用了WP8 我有这个:C# WP8中signar的使用,c#,windows-phone-8,signalr,C#,Windows Phone 8,Signalr,我有一个WindowsPhone8客户端 我正在使用信号器与我的服务器通信 我需要我的用户界面更新来自我的服务器的消息 我知道服务器部分是正确的,因为我设置了断点并使用了HTML5客户端 问题在于WP8 我以前从未使用过WP8,所以我不确定我是否正确使用了WP8 我有这个: public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCac
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
{
UpdateConnectionState("Not Connected");
}
else
{
UpdateConnectionState(string.Format("Success! Connected with client connection id {0}", connection.ConnectionId));
hubuserid = connection.ConnectionId;
//not important for now LogIn();
}
});
connection.Received += data =>
{
UpdateConnectionState(data);
};
connection.Error += ex =>
{
UpdateConnectionState(string.Format("An error occurred {0}", ex.Message));
};
connection.Closed += () =>
{
UpdateConnectionState(string.Format("Connection with client id {0} closed", connection.ConnectionId));
};
connection.Reconnected += () =>
{
UpdateConnectionState("The connection was re-established");
};
}
我的UI最初表示已建立连接
它现在正在接收来自我所停留的服务器的消息。我也试过:
private async void UpdateTime(string data)
{
await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
txtInfo.Text = data;
});
}
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
proxy.On<string>("internetUpTime", UpdateTime);
connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
{
UpdateConnectionState("Not Connected");
}
else
{
UpdateConnectionState(string.Format("Success! Connected with client connection id {0}", connection.ConnectionId));
hubuserid = connection.ConnectionId;
}
});
//connection.Received += data =>
//{
// UpdateConnectionState(data);
//};
connection.Error += ex =>
{
UpdateConnectionState(string.Format("An error occurred {0}", ex.Message));
};
connection.Closed += () =>
{
UpdateConnectionState(string.Format("Connection with client id {0} closed", connection.ConnectionId));
};
connection.Reconnected += () =>
{
UpdateConnectionState("The connection was re-established");
};
}
private async void UpdateTime(字符串数据)
{
wait dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,()=>
{
txtInfo.Text=数据;
});
}
公共主页()
{
this.InitializeComponent();
this.NavigationCacheMode=NavigationCacheMode.Required;
On(“internetUpTime”,UpdateTime);
connection.Start().ContinueWith(任务=>
{
if(task.IsFaulted)
{
UpdateConnectionState(“未连接”);
}
其他的
{
UpdateConnectionState(string.Format(“Success!已连接到客户端连接id{0}”,connection.ConnectionId));
hubuserid=connection.ConnectionId;
}
});
//连接。已接收+=数据=>
//{
//更新连接状态(数据);
//};
connection.Error+=ex=>
{
UpdateConnectionState(string.Format(“发生错误{0}”,例如Message));
};
连接。关闭+=()=>
{
UpdateConnectionState(string.Format(“与客户端id{0}的连接已关闭”,Connection.ConnectionId));
};
连接。重新连接+=()=>
{
UpdateConnectionState(“已重新建立连接”);
};
}
哪种方法是正确的方法?我的代码有什么问题
谢谢要处理来自服务器的呼叫,请使用以下语法:
proxy.On<PckType>("broadcastMessage", msg => {});
SignalR充当RPC服务,这意味着从客户端调用的方法必须存在于服务器上,反之亦然。当然,这只适用于
Hub
方法。那么问题到底在哪里呢?如果在WP8代码中放置断点,会发生什么情况?它会中断吗?您好,感谢您花时间回复。就是这样。连接完成后,我似乎无法从服务器接收消息。我知道服务器正在向hubid发送消息,但客户端没有接收到消息。首先,我应该使用哪种代码?我从网上找到的代码中列出了两种方法。接收端的断点在调用Start后,您的代码是否进入了继续任务?抱歉,突然离开。您应该使用proxy.On(“broadcastMessage”,msg=>{})代码>处理来自服务器的呼叫。没问题。一旦开始工作,请立即汇报。如果仍然存在问题,请更新客户端代码并发布服务器代码以进行澄清。就这一个事件。厚颜无耻的请求,但如果我使用vm ware运行ide,你知道如何运行wp8模拟器吗?不幸的是,不知道。我使用的是parallels,它在那里工作得很有魅力。嗨,没关系:)就像我说的厚颜无耻。但是,在什么上下文中你指的是parallels?我使用的是parallels,一种虚拟化环境。但我想你是在Windows7上,或者是在没有安装Windows8的地方,对吧?嗨,是的。w7上的VMware ware具有虚拟w8安装
Clients.Caller.broadcastMessage(pck);