I have a WCF data service [WebGet] method returning an int. (no of products in products table)
How can I read it’s result?
The method works i checked with the browser.
public void ProductsCount()
{
ctx.BeginExecute<int>(new Uri(uriBase + "/GetNoProducts"), GetProductsCountCompleted, ctx);
}
public void GetProductsCountCompleted(IAsyncResult result)
{
inventory_db_bigEntities context=result.AsyncState as inventory_db_bigEntities;
var x = context.EndExecute<int>(result);
//how do i read the int out of the x variable
}
UPDATE
Maybe BeginExecute and EndExecute is not the way to go for it.
In the browser window the webget method returns:
“<GetNoProducts p1:type=”Edm.Int32″>223863</GetNoProducts>”
What’s wrong with your example? EndExecute should do the trick…just call FirstOrDefault() to get the primitive value. Alternatively, if you’re not using SL, you can do it synchronously:
http://msdn.microsoft.com/en-us/library/hh230677.aspx#ExecutePrimitiveValue