My friend and I just created a WCF data service and would like to consume it with a Windows Phone 8 client. For the WCF data service part, the OData is proved to work with a windows form project which an do CRUD for the database.
So to get WP8 consume WCF Data Service, we followed the tutorial step by step and downloaded the sample code on the MSDN tutorial http://msdn.microsoft.com/en-us/library/windows/apps/hh394007(v=vs.105).aspx
However,the examples don't work.There's no display of data from database on the phone.
We find the
Customers.LoadAsync(Query)
under function public void LoadData
in MainViewModel Class
doesn't load the XML data in :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);
}
We modified the function OnCustomerLoaded to display the error message if there's any:
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;
}
We get the following error:
We are using VS2012 premium, created Windows Phone 8 with data bind project, using OData 5.0.0.
We have to admit that this error may not be the root cause of the problem, but we can't figure it out since we are new to it. We appreciate if anyone can point out what shall we change to make the example work if this is not the error root.
Thanks so much!!