I am consuming a Odata end point in my web API and trying return JSON response from the API.My controller is like below
public class GetEmployeesDEVController : ApiController
{
[HttpGet]
public async Task<EmployeeDTO.RootObject> Get()
{
EmployeeDTO.RootObject returnObj = new EmployeeDTO.RootObject();
var responsedata = "";
using (var client_Core = new HttpClient())
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
Uri uri = new Uri(BaseURL_Core);
client_Core.BaseAddress = uri;
client_Core.DefaultRequestHeaders.Accept.Clear();
client_Core.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client_Core.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray_Core));
string core_URL = BaseURL_Core;
var response = client_Core.GetAsync(core_URL).Result;
responsedata = await response.Content.ReadAsStringAsync();
returnObj = JsonConvert.DeserializeObject<EmployeeDTO.RootObject>(responsedata);
return returnObj;
}
Here EmployeeDTO is the model class for the Odata response. When I call my API it returns nulls and dont return any data. But the responsedata holds JSON that has data. Screenshot of responsedata and returnObj is below
I am not sure if I am missing anything here. All I need to get from my API is the exact response from the Odata endpoint that is stored in responsedata


client_Core.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));you will get json value inresponsedatathen why you are trying to convert in json again, justreturn responsedata;