Now we will create a reference service. For creating a reference service right click on "WinOData" under "Soluton 'WinOData'" and select "Add Service Reference.."
Add the following line at the top of the class among the other "using" statements.
using WinOData.odataService;
We will code a new method CategoryProductList(), we will need this new method as we will be firing async queries and for that the method needs to be async and the SampleDataSource() method cannot be made into async.
async void CategoryProductList()
{
DemoService service = new DemoService(new Uri("http://services.odata.org/(S(1mwfq3psy4zegts3wuo5yt4i))/OData/OData.svc"));
// The below code is required if the service expects authentication
// service.Credentials = new NetworkCredential("username", "password", "domain");
var query = from p in service.Categories
select p;
DataServiceQuery<Category> dqs = (DataServiceQuery<Category>)(query);
TaskFactory<IEnumerable<Category>> tf = new TaskFactory<IEnumerable<Category>>();
IEnumerable<Category> b = await tf.FromAsync(dqs.BeginExecute(null, null),
iar => dqs.EndExecute(iar));
foreach (Category cat in b)
{
var group1 = new SampleDataGroup("cat"+cat.ID,
cat.Name,
"",
"Assets/DarkGray.png",
"");
var oquery = from op in service.Products
where op.Category.ID == cat.ID
select op;
DataServiceQuery<Product> odqs = (DataServiceQuery<Product>)(oquery);
TaskFactory<IEnumerable<Product>> otf = new TaskFactory<IEnumerable<Product>>();
IEnumerable<Product> ob = await otf.FromAsync(odqs.BeginExecute(null, null),
iar => odqs.EndExecute(iar));
foreach (Product products in ob)
{
string description = String.Format("Description:{0}\nPrice:{1}\nRating:{2}\n", products.Description, products.Price, products.Rating);
group1.Items.Add(new SampleDataItem("product"+products.ID,
products.Name,
"",
"Assets/LightGray.png",
"",
description,
group1));
}
this.AllGroups.Add(group1);
}
}
public SampleDataSource()
{
CategoryProductList();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
19 | |
11 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |