Azure Function
The request channel timed out while waiting for a reply after 00:01:59.9687488
Category: "The request channel timed out while waiting for a reply after 00:01:59.9687488.",Azure,Azure Function,Azure function trigger,Dynamics 365,OrganizationWebProxyClient timeout error Author: HIMBAP Date: 1 year ago Comments: 0

This post is about
“The request channel timed out while waiting for a reply after 00:01:59.9687488. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.” error, we got this error in our Azure function where we are updating Dynamics 365 CE records. We are going to discussed how we fixed it.

We used following code in our Azure function to connect to Dynamics 365 CE.

 private static OrganizationWebProxyClient GetCRMService(TraceWriter log) {

  var aadInstance = "";
  var organizationUrl = "";

  var tenantId = "8....";

  var clientId = "5...";

  var clientkey = "qZXgfddd.....";

  var clientcred = new ClientCredential(clientId, clientkey);

  var authenticationContext = new AuthenticationContext(aadInstance + tenantId);

  var authenticationResult = authenticationContext.AcquireTokenAsync(organizationUrl, clientcred);

  var requestedToken = authenticationResult.Result.AccessToken;

  var sdkService = new OrganizationWebProxyClient(GetServiceUrl(organizationUrl), false);
  sdkService.HeaderToken = requestedToken;
  return sdkService;

Please see our earlier post to know, how to connect to Dynamics 365 CE from Azure function.

Recently our Azure function started failing and when we checked logs it was timeout error. It was throwing timout error after two minute as default timeout limit for OrganizationWebProxy is 2 minute. But we can override this setting. We can get OrganizationWebProxyClient by passing following parameters.

public OrganizationWebProxyClient(
    Uri uri,
    TimeSpan timeout,
    Assembly strongTypeAssembly

Reference: Dynamics 365 CE SDK

To fix this issue we used following code

var sdkService = new OrganizationWebProxyClient(GetServiceUrl(organizationUrl),new TimeSpan(0, 10, 0), false);

We used 10 minute here, but you can change it based on your requirement.

We learned how to fixed OrganizationWebProxyClient timeout issue by passing TimeSpan parameter. Hope it will help someone. Stay tuned for more Dynamics 365 CE Contents !!

Source: Mahendra Pal