Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

Converting CRM Web Api response JSON to CRM Entity in C#

$
0
0

I have been writing some code to access CRM Web API through C# console application.

I am successfully able to fetch data from CRM after registring my app with Azure AD Service and providing client ID to  during authentication process.

Upon  request I am getting  data in JSON format so I decided to create an early bound class for organization service and use it in order to convert JSON to crm entity object. Following is the code which I am using to do that. CrmEntities is  early bound class generated from organization service.

 using (var httpClient = GetHttpClient())
            {
                responseMessage =
                await httpClient.GetAsync(URI + "(" + entityId.ToString() + ")");
                //The URL will change in 2016 to include the API version - api/data/v8.0/systemusers
                if (responseMessage.IsSuccessStatusCode)
                {
                    entitySource =
                        (new_entity)
                            earlyBoundSerializer.ReadObject(responseMessage.Content.ReadAsStreamAsync().Result);
                    entitySource = JsonConvert.DeserializeObject<CrmEntities.new_entity>(responseMessage.Content.ReadAsStringAsync().Result);
                    //jRetrieveResponse = JObject.Parse(responseMessage.Content.ReadAsStringAsync().Result);
                }
                else
                    return null;
            }


Now  here comes issue.

When I am converting Json to  new_Entity  its not throwing any exception but when I look at new_entity object  all the values are empty. no data got populated. any idea how to  overcome this?


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>