您好,這是我的第一個問題,我創建了一個託管在Azure上的Web服務......並且我有一個Windows Phone客戶端應用程序和一個Windows 8 metro客戶端應用程序,現在當我連接了WP7應用程序,我用這些方法來得到服務的東西在Windows Phone:已完成的Web服務事件不顯示在Metro Windows 8應用程序開發中
TimeTierBusiness.BusinessesClient client = new TimeTierBusiness.BusinessesClient();
client.GetAllCompleted += new EventHandler<TimeTierBusiness.GetAllCompletedEventArgs>(client_GetAllCompleted);
client.GetAllAsync();
和得到的結果,我只是去了client_GetAllCompleted,你可以看到如下:
void client_GetAllCompleted(object sender, TimeTierBusiness.GetAllCompletedEventArgs e)
{
listNearbyBusinesses.ItemsSource = e.Result;
myPopup.IsOpen = false;
}
現在在Windows 8地鐵上,重新是沒有GetAllCompleted事件,我可以添加到獲得結果,當我呼叫客戶端在Windows 8時,我所得到的是GetAllAsync()方法,這是等待...
任何幫助將不勝感激,因爲我現在不能在我的metro應用使用此服務
謝謝:)
確定這樣的解決方案是,創建一個異步方法,請參見下面的代碼:
//My WCF Service Client
TimeTierBusiness.BusinessesClient bClient = new TimeTierBusiness.BusinessesClient();
//The list I am going to get from the service
public List<TimeTierBusiness.BusinessRatingViewModel> listBusinessViewModel;
這種方法異步填寫服務列表
private async void GetAllAsyc()
{
System.Collections.ObjectModel.ObservableCollection<TimeTierBusiness.BusinessRatingViewModel> x = await bClient.GetAllAsync();
listBusinessViewModel = x.ToList();
ItemListView.ItemsSource = listBusinessViewModel;
}
嘿感謝我的工作了:)很開心,我也會張貼代碼正是我如何解決它......從你的鏈接幫助:) – fattikus 2012-04-20 16:06:43