我有一个调用 Dataverse API 的 ASP.NET MVC 解决方案,与(
即将弃用)WS-Trust 连接相比,使用
CrmServiceClient
和 AuthType=OAuth
时我发现性能显着下降( AuthType=Office365
)
这是用于创建
CrmServiceClient
连接的代码 (AuthType=OAuth
)
var conn = new CrmServiceClient(connectionString);
var service = (IOrganizationService) conn.OrganizationWebProxyClient ?? conn.OrganizationServiceProxy;
这是用于创建 WS-Trust 连接的代码 (
AuthType=Office365
)
var target = CrmConnection.Parse(connectionString);
target.ServiceConfigurationInstanceMode = ServiceConfigurationInstanceMode.PerName;
var service = (OrganizationService) CrmConfigurationManager.CreateService(target, "DataverseServiceName");
有人遇到过同样的问题吗?
在我们的例子中,问题是我们使用的是旧版本的 CrmSdk,使用最新版本 (9.0.2.42) 解决了我们的问题 https://www.nuget.org/packages/Microsoft.CrmSdk.CoreAssemblies/9.0.2.42
设置来电显示时我们也遇到模拟问题 (https://learn.microsoft.com/en-us/dotnet/api/microsoft.xrm.tooling.connector.crmserviceclient.callerid?view=dataverse-sdk-最新#microsoft-xrm-tooling-connector-crmserviceclient-callerid),如果您正在运行多个线程并启动与不同呼叫者 ID 的多个连接,我们发现它不是线程安全的,并且一些模拟一个用户的调用可能会被另一个用户混淆用户即使:
disablecrossthreadsafeties 设置为 false (https://learn.microsoft.com/en-us/dotnet/api/microsoft.xrm.tooling.connector.crmserviceclient.disablecrossthreadsafeties?view=dataverse-sdk-latest#microsoft-xrm -工具连接器-crmserviceclient-禁用跨线程安全)
RequireNewInstance 设置为 true (https://learn.microsoft.com/en-us/power-apps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect#connection -字符串参数)
我们最终不得不缓存每个呼叫者ID的每个IOrganizationService以防止它