Quote:
[ResponseType(typeof(Products))]
public IQueryable<Products> GetProducts()
The
ResponseType
value doesn't match the type you are returning. But since you're returning a concrete type, rather than an
IHttpActionResult
, that attribute is not required on this action.
Quote:
HttpResponseMessage response = client.GetAsync("api/Products").Result;
...
var products = response.Content.ReadAsStringAsync().Result;
grvProducts.DataSource = products;
Don't use
.Result
to synchronously get the result of a task. Instead, make your method
async
, and
await
the task.
Also,
ReadAsStringAsync
will return a
string
, which is not a suitable
DataSource
. Either use
ReadAsAsync<IEnumerable<Products>>()
, or parse the JSON string returned from
ReadAsStringAsync
into a list of
Products
entities.
Beyond that, if you're not getting any data back, then that means there is no data in your database. You need to check the database to find out why.