简体   繁体   English

Microsoft.Xrm.Tooling.Connector高内存分配

[英]Microsoft.Xrm.Tooling.Connector High Memory Allocation

I am currently going through the process of upgrading our product CRM SDK and the main change I have encountered is that instead of connecting to the Xrm service and creating my IOrganizationService using the tried and trusted method of: 我目前正在完成升级产品CRM SDK的过程,我遇到的主要变化是使用以下尝试和信任的方法连接到Xrm服务并创建我的IOrganizationService:

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

I am now having to utilise the CrmServiceClient from the Tooling namespace: 我现在不得不使用Tooling命名空间中的CrmServiceClient:

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

Now this is all fine except from one major issue...memory. 现在这一切都很好,除了一个主要问题......记忆。

Using the older Xrm.Client method you were able to specify the Service Configuration Instance Mode (which defaulted to ServiceConfigurationInstanceMode.PerName). 使用较旧的Xrm.Client方法,您可以指定服务配置实例模式(默认为ServiceConfigurationInstanceMode.PerName)。 What this meant is that the service was reused if the same application called the create multiple times. 这意味着如果同一个应用程序多次调用create,则会重用该服务。 This kept the memory footprint low. 这使内存占用率降低。 The below image show the amount of allocated memory after calling to create a service instance 100 times 下图显示了在调用创建服务实例100次后分配的内存量

在此输入图像描述

However, using the newer method you cannot set this instance mode anywhere and it seems that a brand new connection is created every time whether you want it or not. 但是,使用较新的方法无法在任何地方设置此实例模式,似乎每次都会创建一个全新的连接,无论您是否需要它。 Here are the results of the same test: 以下是同一测试的结果: 在此输入图像描述

As you can see, with every new connection, more and more memory is allocated. 如您所见,每次新连接都会分配越来越多的内存。 I can;t see anywhere that i can tell it to reuse the service. 我无法看到我可以告诉它重用该服务的任何地方。

So what I'm basically asking is, am I going about this in the wrong way? 所以我基本上要问的是,我是以错误的方式解决这个问题吗? Should I be creating and caching everything myself? 我应该自己创建和缓存一切吗? Are there hidden classes/methods that I am missing? 我缺少隐藏的课程/方法吗? Any help would be greatly appreciated. 任何帮助将不胜感激。

The latest SDK (8.2.0.1) caches and resuses the connection as long as the connectionstring does not inclue RequireNewInstance=true . 只要连接RequireNewInstance=trueRequireNewInstance=true ,最新的SDK (8.2.0.1)就会缓存并重新使用连接。

One thing worth noting is even if you new up another CrmServiceClient with a unique connection string (pointing to a different CRM organization), but the connection string does not include RequireNewInstance=true , the CrmServiceClient will reuse the previous cached connection. 值得注意的是,即使您使用唯一的连接字符串(指向不同的CRM组织)新建另一个CrmServiceClient ,但连接字符串不包含RequireNewInstance=trueCrmServiceClient也将重用以前的缓存连接。

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 out the guid and ORG1 friendly name both times. 两次打印guid和ORG1友好名称。 If you pass RequireNewInstance=true in connectionstring2 then you will see ORG2 printed out. 如果您在connectionstring2传递RequireNewInstance=true ,那么您将看到ORG2打印出来。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Microsoft.Xrm.Tooling创建服务和上下文 - Using Microsoft.Xrm.Tooling to create a service and context 365更新后无法使用Xrm.Tooling.Connector连接到Dynamics 365 - Can't connect to Dynamics 365 with Xrm.Tooling.Connector after 365 update Dynamics CRM Xrm工具错误“无法分配2147483647字节的托管内存缓冲区。” - Dynamics CRM Xrm Tooling error “Failed to allocate a managed memory buffer of 2147483647 bytes.” 为什么在Dynamics 365 XRM工具SDK中使用IOrganizationService而不是CrmServiceClient? - Why use IOrganizationService instead of CrmServiceClient in Dynamics 365 XRM tooling SDK? Microsoft SDK XRM GetProxy“ NoURL” - Microsoft SDK XRM GetProxy “NoURL” Microsoft.Xrm.Sdk.Client HTTP压缩 - Microsoft.Xrm.Sdk.Client HTTP compresssion 无法访问Microsoft.Xrm命名空间 - Can't access Microsoft.Xrm namespace 如何使用 Dynamics 365 XRM Tooling SDK 通过主 ID 一般获取实体记录的枚举集 - How to generically get enumerated set of entity records by primary id with Dynamics 365 XRM Tooling SDK Microsoft.Xrm.Sdk.DataCollection的新实例/构造函数<T> - new instance / constructor of Microsoft.Xrm.Sdk.DataCollection<T> 尝试将删除记录 function 添加到我的 web 应用程序,该应用程序使用 XRM 工具更新/编辑 Dynamics 365 中的记录并不断收到此错误? - Trying to add a delete record function to my web app that uses XRM tooling to update/edit records in Dynamics 365 and keep getting this error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM