web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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;
        }

I have the same question (0)
  • Suggested answer
    Madalina Toma Profile Picture
    on at

    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!

  • John742 Profile Picture
    10 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 73 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans