LoadAsync在带有WCF数据服务的Windows Phone 8中不起作用

时间:2014-10-17 08:21:07

标签: c# wcf windows-phone-8 odata wcf-data-services-client

我的朋友和我刚刚创建了一个WCF数据服务,并希望使用Windows Phone 8客户端来使用它。对于WCF数据服务部分,OData被证明可以与Windows表单项目一起使用,该项目为数据库执行CRUD。

为了让WP8使用WCF数据服务,我们按照教程一步一步地下载了MSDN教程中的示例代码 http://msdn.microsoft.com/en-us/library/windows/apps/hh394007(v=vs.105).aspx

但是,这些示例不起作用。手机上的数据库中没有数据显示。

我们找到了 Customers.LoadAsync(Query)public void LoadData中的函数MainViewModel Class下,不会在http://services.odata.org/Northwind/Northwind.svc/Customers()中加载XML数据。

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 premium,使用OData 5.0.0创建带有数据绑定项目的Windows Phone 8。

我们必须承认,这个错误可能不是问题的根本原因,但我们无法弄明白,因为我们不熟悉它。如果这不是错误根,我们感谢任何人都可以指出我们应该改变什么以使示例有效。

非常感谢!!

1 个答案:

答案 0 :(得分:0)

这看起来您的应用无法访问互联网,这可能是由于设置了您的WP模拟器问题造成的。

您可以先试用内置的网络浏览器,然后检查它是否可以访问互联网。如果没有,您可以转到Hyper-V配置页面,尝试更改网络适配器设置,或参阅以下page了解详细信息。