Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Dynamics 365 webApi - Creating 3rd record times out

(0) ShareShare
ReportReport
Posted on by 10

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);
            return createResponse;
        }

  • John742 Profile Picture
    10 on at
    RE: Dynamics 365 webApi - Creating 3rd record times out

    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.

  • Suggested answer
    Madalina Toma Profile Picture
    on at
    RE: Dynamics 365 webApi - Creating 3rd record times out

    Hello John,

    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.

    Thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106 Most Valuable Professional

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 102

Overall leaderboard

Product updates

Dynamics 365 release plans