Click here to Skip to main content
15,889,804 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am very new to OData service. I have created a WebAPi Odata Service with Entity Framework. I am able to get the data from service using HttpClient. I am trying to pass id value to find a record. I am not sure how to pass value to service.

Below is my code:

public string GetEquipmentDetails(int catergoryID)
{
HttpClient client1 = new HttpClient();

client1.BaseAddress = new Uri("http://localhost:50390/");
client1.DefaultRequestHeaders.ExpectContinue = false;
client1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

HttpResponseMessage reponse = client1.GetAsync("EquipmentCategories/" + catergoryID).Result;
var equipmentDetails = reponse.Content.ReadAsAsync<odatarespoe><equipmentdetails>>().Result;
return "done";
}

But its returning an error like not acceptable.

I tried like below also but not able to get it.

HttpResponseMessage reponse = client1.GetAsync("EquipmentCategories(" + catergoryID+")").Result;

Below is OData code:
[EnableQuery]
public IHttpActionResult GetEquipmentCategory([FromODataUri] int key)
{

var results =db.Get_EquipmentDetails(1);

return Ok(results);
}

Please help me on this. How to send parameter to OData service. Please let me know if I am not clear.

Thanks!!
Posted
Comments
Richard Deeming 13-Jan-16 9:23am    
Don't paraphrase the error; post the exact error message.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900