Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 release wave 1Discover the latest updates and new features to Dynamics 365 planned through September 2020
Release overview guides and videos Release Plan | Preview 2020 Release Wave 1 Timeline
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
I am working on putting together a data model to allow me to create records within Dynamics 365 using the webAPI. I can successfully create, update, and query records. However, I run into a strange issue when creating multiple records. I can create two records but on the third one it times out. Even if I extend the timeout to be 10 mintutes it still eventually times out. What am I missing on this? Here is the code I am using
virtual public HttpResponseMessage CreateRecordRequest(HttpClient client)
HttpRequestMessage createRequest = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress + this.WebApiType);
createRequest.Content = new StringContent(this.ToJObject().ToString());
createRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
HttpResponseMessage createResponse = client.SendAsync(createRequest, HttpCompletionOption.ResponseHeadersRead).Result;
this.Uri = new Uri(createResponse.Headers.GetValues("OData-EntityId").FirstOrDefault());
this.Id = Uri.ToString().Substring(Uri.ToString().Length - 37, 36);
Thank you for posting the question.
Regarding the behaviour you encounter, please find below several points to improve in the code snippet above:
- from what I can see your response can be sent as Async, based on what I remember from one of the old cases I had, while sending an Async request or response, the system will not have a good visibility over the execution pipeline and because of this your messages might not be in the proper order and this way your request can silently fail and at the end be killed by the system with a generic error
- looking at the code the HttpRequestMessage in our documentation and also in the RFC documentation mentioned in the .Net Framework documentation, I am unable to clarify if the class can be used sync or Async, but just to confirm, you can try to see if this type of request will provide the correct result using the HttpClient.SendRequestAsync Method
- by default the D365 CE has a timeout at least on the Sandbox level for 2 minutes, depending on the logic behind, my recommendation is not to set it for a longer period of time, but on the other hand this contradicts the Async principle where the Async request will only start to be executed when the system is free
- Looking at the .Net Framework documentation I can see the Send request is only Async:https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.sendasync?view=netframework-4.6.1
In order to confirm my findings regarding the Sync and Async request, we will need to take a Fiddler trace, which as you know contains confidential details, therefore if you will like to continue this investigation on Microsoft side, please raise a service request and attach a Fiddler trace to it with the faulty request, or if you have those details, inside the Fiddler trace there is a RequestId or an ActivityId, something similar with x-ms-service-request-id, you can paste the request Id and the date and time of the request in order for us to confirm the details above.
So the issue ended up being that I was not using HttpResponseMessage.Dispose() after making the calls. I had a using statement for the HttpClient but I guess it was too big. Once I started using Dispose() everything started working.
Business Applications communities