I've got an ASP.NET MVC solution that calls the Dataverse API and I'm seeing a significant performance degradation when using CrmServiceClient
and AuthType=OAuth
compared with the (soon to be deprecated) WS-Trust connection (AuthType=Office365
)
This is the code used for creating the CrmServiceClient
connection (AuthType=OAuth
)
var conn = new CrmServiceClient(connectionString);
var service = (IOrganizationService) conn.OrganizationWebProxyClient ?? conn.OrganizationServiceProxy;
and this is the code used for creating WS-Trust connection (AuthType=Office365
)
var target = CrmConnection.Parse(connectionString);
target.ServiceConfigurationInstanceMode = ServiceConfigurationInstanceMode.PerName;
var service = (OrganizationService) CrmConfigurationManager.CreateService(target, "DataverseServiceName");
Has anyone experienced the same issue?
In our case the issue was that we were using an old version of the CrmSdk, using the latest version (9.0.2.42) solved our problem https://www.nuget.org/packages/Microsoft.CrmSdk.CoreAssemblies/9.0.2.42
We also have issues with impersonation when setting the caller id (https://learn.microsoft.com/en-us/dotnet/api/microsoft.xrm.tooling.connector.crmserviceclient.callerid?view=dataverse-sdk-latest#microsoft-xrm-tooling-connector-crmserviceclient-callerid), if you are running several threads and initiating multiple connections with different callerids, we found that it's not thread safe and some calls to impersonate one user might get mixed up by another user even if:
disablecrossthreadsafeties is set to false (https://learn.microsoft.com/en-us/dotnet/api/microsoft.xrm.tooling.connector.crmserviceclient.disablecrossthreadsafeties?view=dataverse-sdk-latest#microsoft-xrm-tooling-connector-crmserviceclient-disablecrossthreadsafeties)
RequireNewInstance is set to true (https://learn.microsoft.com/en-us/power-apps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect#connection-string-parameters)
We ended up having to cache each IOrganizationService per callerid to prevent it