locked
wcf data service [WebGet] method returning an int RRS feed

  • Question

  • 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<int> and EndExecute<int> is not the way to go for it.

    In the browser window the webget method returns:

    <GetNoProducts p1:type="Edm.Int32">223863</GetNoProducts>

    • Edited by PaulRusu Wednesday, December 14, 2011 2:17 PM
    Wednesday, December 14, 2011 2:14 PM

All replies

  • Hi PaulRusu,

     

    change this  var x = context.EndExecute<int>(result); to

     var x = (context.EndExecute<int>(result)).FirstORDefault();


    and check value in x
    • Edited by Rahul-P Tuesday, December 20, 2011 8:29 AM
    • Proposed as answer by Rahul-P Tuesday, December 20, 2011 11:27 AM
    Tuesday, December 20, 2011 8:28 AM
  • Hi Paul,

     The Data Services client library doesn't support reading primitive values from a service operation.
     You should use HttpWebRequest to make the request and XLinq apis to read the return value of the service operation.

     Phani


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Tuesday, January 17, 2012 10:02 PM
    Moderator
  • Phani,

    Maybe your answer should have also included, "The Data Services client library doesn't support reading primitive values or Complex Objects from a service operation"


    Haroon
    Saturday, January 21, 2012 6:45 AM