2014-10-17 117 views
0

我的朋友和我刚刚创建了一个WCF数据服务,并希望通过Windows Phone 8客户端使用它。对于WCF数据服务部分,OData被证明可以与Windows窗体项目一起工作,该窗体项目对数据库执行CRUD操作。LoadAsync无法在Windows Phone 8中使用WCF数据服务

因此,要获得WP8使用WCF数据服务,我们遵循一步教程一步,在MSDN下载教程示例代码 http://msdn.microsoft.com/en-us/library/windows/apps/hh394007(v=vs.105).aspx

然而,这些例子不work.There没有从数据的显示数据库在手机上。

我们发现在MainViewModel ClassCustomers.LoadAsync(Query) 下功能public void LoadData在不加载XML数据:http://services.odata.org/Northwind/Northwind.svc/Customers()

public void LoadData() 
        { 
            // Instantiate the context and binding collection. 
            _context = new NorthwindEntities(_rootUri); 
            Customers = new DataServiceCollection<Customer>(_context); 

            // Specify an OData query that returns all customers. 
            var query = from cust in _context.Customers 
                        select cust; 

            // Load the customer data. 
            Customers.LoadAsync(query); 
        } 

我们修改了功能OnCustomerLoaded如果有任何显示错误消息:

private void OnCustomersLoaded(object sender, LoadCompletedEventArgs e) 
     { 
      if (e.Error != null) 
      { 

       MessageBox.Show(e.Error.Message+e.Error.InnerException); 

      } 
      // Make sure that we load all pages of the Customers feed. 
      if (Staffs.Continuation != null) 
      { 
       Staffs.LoadNextPartialSetAsync(); 
      } 
      //MessageBox.Show(Staffs.ToString()); 
      IsDataLoaded = true; 
     } 

我们得到以下错误:

Error from LoadAsync method

我们使用VS2012溢价,使用OData 5.0.0创建带有数据绑定项目的Windows Phone 8。

我们不得不承认,这个错误可能不是问题的根本原因,但我们无法弄清楚,因为我们是新手。我们非常感谢,如果有人能指出我们应该改变什么来让这个例子起作用,如果这不是错误根源的话。

非常感谢!

+0

如果你有'NotFound'错误,序列化数据时可能会失败。尝试更新您的服务参考。找出问题的一个好方法是在服务器上启用svc trace日志记录。 – Silvermind 2014-10-18 10:31:23

回答

0

这看起来像您的应用程序无法访问互联网,它可能是由您的WP模拟器设置问题引起的。

您可以先尝试内置的Internet Explorer,并检查它是否具有互联网连接。如果没有,则可以进入Hyper-V配置页面,然后尝试更改网络适配器设置,或者参阅以下page了解详细信息。