0
我是Windows 8平臺編程的新手,所以我被卡住了。在項目中,我使用SignalR(我下載並安裝正確包),並試圖簡單地實現連接,使用此代碼:http://code.msdn.microsoft.com/wpapps/Windows-Phone-8-Chat-1fa5eccfWindows phone 8 signalR連接方法
public Play()
{
InitializeComponent();
_connection = new HubConnection(websiteUrl);
_myHub = _connection.CreateHubProxy("GameManager");
InitializeConnection();
}
public async Task InitializeConnection()
{
try
{
var obj = new
{
header = 0,
data = App.login,
};
var result = JsonConvert.SerializeObject(obj, Formatting.Indented);
await _connection.Start();
await _myHub.Invoke("SendConnection", result);
IsConnected = true;
_myHub.On<string>("recieved", data =>
{
if (OnRecieved != null)
{
OnRecieved(this, new ChatEventArgs { MessageSent = data });
System.Diagnostics.Debug.WriteLine("DATA : " + data);
}
});
if (OnConnected != null)
{
OnConnected(this, new EventArgs());
}
}
catch
{
}
}
websiteUrl是網站我想達到的URL。
但是,我沒有成功接收來自服務器的響應(並且我知道如果連接成功,它會返回一些內容)。
我需要做更多或不同的事情嗎?謝謝你的幫助。
它的工作,謝謝! – Lexou
謝謝Lexou。請檢查他們討論過的以下鏈接以啓用localhost環境的端口。 http://stackoverflow.com/questions/18371131/signalr-hub-connectivity-from-windows-phone-8 – Thanigainathan