Microsoft.Xrm.Tooling.Connector High memory allocation

I am currently reviewing the process of updating our CRM SDK product, and the main change I came across is that instead of connecting to the Xrm service and creating my IOrganizationService using a proven and reliable method:

var connection = CrmConnection.Parse(connectionString); var service = new OrganizationService(connection); 

Now I need to use CrmServiceClient from the Tooling namespace:

  CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString).OrganizationServiceProxy; 

Now everything is fine, except for one important problem ... memory.

Using the older Xrm.Client method, you were able to specify the instance mode of the configuration service (which was used by default for ServiceConfigurationInstanceMode.PerName). This means that the service was reused if the same application was called create several times. This reduced the memory area. The image below shows the amount of allocated memory after a call to create a service instance 100 times

enter image description here

However, using the new method, you cannot set this instance mode anywhere, and it seems that a new connection is created each time, whether you want it or not. Here are the results of the same test: enter image description here

As you can see, with each new connection more and more memory is allocated. I can’t see that I can say that it is reusing the service.

So I basically ask, am I wrong about this? Should I create and cache myself? Are there hidden classes / methods that I am missing? Any help would be greatly appreciated.

+5
source share
1 answer

The last SDK (8.2.0.1) caches and reconnects if the connection string does not include RequireNewInstance=true .

It should be noted that even if you add another CrmServiceClient with a unique connection string (pointing to a different CRM organization), but the connection string does not include RequireNewInstance=true , CrmServiceClient will reuse the previous cached connection.

So,

 var connectionString = $@ "Url=https://ORG1.crm.dynamics.com;AuthType=Office365; UserName=USER@DOMAIN.com ;Password=PASSWORD"; var connectionString2 = $@ "Url=https://ORG2.crm.dynamics.com;AuthType=Office365; UserName=USER@DOMAIN.com ;Password=PASSWORD"; var crmSvcClient = new CrmServiceClient(connectionString); ((WhoAmIResponse)crmSvcClient.Execute(new WhoAmIRequest())).OrganizationId.Dump(); crmSvcClient.ConnectedOrgFriendlyName.Dump(); var crmSvcClient2 = new CrmServiceClient(connectionString2); ((WhoAmIResponse)crmSvcClient2.Execute(new WhoAmIRequest())).OrganizationId.Dump(); crmSvcClient2.ConnectedOrgFriendlyName.Dump(); 

Prints the friendly name guid and ORG1 both times. If you pass RequireNewInstance=true in connectionstring2 , you will see an ORG2 printout.

+1
source

Source: https://habr.com/ru/post/1260463/


All Articles