您好,这是我在这里的第一个问题,我创建了一个托管在 Azure 上的 Web 服务......我有一个 Windows 手机客户端应用程序和一个 Windows 8 Metro 客户端应用程序,现在当我连接 wp7 应用程序时,我使用这些方法来获取windows phone 上的服务中的一些东西:
        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 Metro 上,没有可以添加的 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;
    }