Uncategorized

Tip – RequireNewInstance property to handle TimeOut issues while using CrmServiceClient (XrmTooling)

Recently we had created a windows service which was running continuously on our server. The very next day we started getting Timeout exceptions for the OrganizationServiceProxy created using CrmServiceClient using XrmTooling. This was due to session getting expired after 24 hrs.

We decided to investigate on this and came across a way to fix this. We found this attribute “RequireNewInstance” which can be passed in the connection string which did our job.

We included the connection part in our while loop and in that we set RequireNewInstance = false while creating connection using CrmServiceClient, so that it will create new instance only when required and use the existing cached connection when the service is connected and not expired.

Using this we were able to resolve our timeout issue as when the service gets expired it creates a fresh token and caches it, until it expires. there by not impacting the application output.

while(true) 
{
//Had our logic to read the data continously from Azure Bus
var connectObject = new CrmServiceClient($@"AuthType=ClientSecret;url={organizationUrl};ClientId={clientId};ClientSecret={appKey};RequireNewInstance=false");
}