CrmServiceClient connection timeout

The CrmServiceClient class allows you to connect easily to the Common Data Service and execute the API operations offered by the platform. Depending on your particular implementation, you may need to change the connection timeout. This article explains how to apply a custom timeout to a CrmServiceClient intance.

As I covered in my previous article, the CrmServiceClient class has two important properies: OrganizationServiceProxy and OrganizationWebProxyClient. They may let you change the connection timeout that you are looking for. However, this is not the best practice for new implementations. You should use the CrmServiceClient static property MaxConnectionTimeout:

Using CrmServiceClient.MaxConnection property

Previously to the deprecation of OrganizationServiceProxy, you may have used the following option:

Setting Timeout when using OrganizationServiceProxy (deprecated)

The other possible alternative to the CrmServiceClient.MaxConnectionTimeout could be the OrganizationWebProxyClient reference, but I would still not recommend to use this option:

Setting Timeout when using OrganizationWebProxyClient

You can download and test this code from my GitHub repository:

https://github.com/rtebar/Dynamics-Utils/blob/master/Dynamics.Utils/Dynamics.Utils.Tests/ProxyTimeout.cs

Notes: At the time of writing this article, I’m using the package Microsoft.CrmSdk.XrmTooling.CoreAssembly 9.1.0.38 and I’m connecting to an environment whose version is 9.1.0.14744 with 2020 release wave 1 enabled

6 thoughts on “CrmServiceClient connection timeout

  1. Hi Ramon,
    OrganizationServiceProxy is deprecated and will be removed soon. You shouldn’t have to access this property (or even OrganizationWebProxyClient) to set the Timeout
    Juste use this code : CrmServiceClient.MaxConnectionTimeout = new TimeSpan(0,0,15);

    1. Thanks you very much Tanguy! Oh, I completely missed that one. It makes sense to be honest, the fact of having OrganizationServiceProxy and OrganizationWebProxyClient was an overhead. Is there any official documentation about this deprecation?

      1. Haha, you were quicker! Thanks again Tanguy! I’ll update my articles to inform the community about this important change.

  2. Hi Ramon,

    You shouldn’t have to user OrganizationServiceProxy (it’s deprecated and will be removed soon) or even OrganizationWebProxyClient to set Timeout

    Just use the snippet below:
    CrmServiceClient.MaxConnectionTimeout = new TimeSpan(0,0,15);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s