Проблема с подключением к локальной CRM Dynamics 365 из консольного приложения

Есть локальная CRM Dynamics 365. Пытаюсь подключиться к ней из консольного приложения (.Net 6.0). Собственно, пример взят с git библиотеки Microsoft.PowerPlatform.Dataverse.Client. Только я не стал заносить строку подключения в .json, а передаю напрямую:

using Microsoft.Crm.Sdk.Messages;
using Microsoft.Extensions.Configuration;
using Microsoft.PowerPlatform.Dataverse.Client;

namespace PowerPlatform.Dataverse.CodeSamples
{
  /// <summary>
  /// Demonstrates connecting to the Dataverse Organization service and 
  /// executing a message request.
  /// </summary>
  /// <remarks>Set the appropriate Url and Username values for your test
  /// environment in the appsettings.json file before running this program.</remarks>
  /// <see cref="https://docs.microsoft.com/power-apps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect#connection-string-parameters"/>
  /// <permission cref="https://github.com/microsoft/PowerApps-Samples/blob/master/LICENSE"
  /// <author>Peter Hecke</author>
  class Program
  {
    /// <summary>
    /// Contains the application's configuration settings. 
    /// </summary>
    IConfiguration Configuration { get; }


    /// <summary>
    /// Constructor. Loads the application configuration settings from a JSON file.
    /// </summary>
    Program()
    {
        // Get the path to the appsettings file. If the environment variable is set,
        // use that file path. Otherwise, use the runtime folder's settings file.
        string? path = Environment.GetEnvironmentVariable("DATAVERSE_APPSETTINGS");
        if (path == null) path = "appsettings.json";

        // Load the app's configuration settings from the JSON file.
        //Configuration = new ConfigurationBuilder()
            //.AddJsonFile(path, optional: false, reloadOnChange: true)
            //.Build();
    }
    static void Main(string[] args)
    {
        Program app = new();
        string connectionString = "AuthType=AD; Username=myUserName; Password=myPassword; " +
            "Url=http://srv-democrm.axapta.local/;" +
            "AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;" +
            "RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;";

        // Create a Dataverse service client using the default connection string.
        ServiceClient serviceClient =
            new(connectionString);

        // Send a WhoAmI message request to the Organization service to obtain  
        // information about the logged on user.
        WhoAmIResponse resp = (WhoAmIResponse)serviceClient.Execute(new WhoAmIRequest());
        Console.WriteLine("User ID is {0}.", resp.UserId);

        // Pause program execution before resource cleanup.
        Console.WriteLine("Press any key to continue.");
        Console.ReadKey();
        serviceClient.Dispose();
    }
  }
}

При создании ServiceClient выбрасывается исключение:

PlatformNotSupportedException: Xrm.Sdk WSDL
Unhandled exception. Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseConnectionException: One or more errors occurred. (Xrm.Sdk WSDL)
 ---> System.AggregateException: One or more errors occurred. (Xrm.Sdk WSDL)
 ---> System.PlatformNotSupportedException: Xrm.Sdk WSDL
   at Microsoft.PowerPlatform.Dataverse.Client.Connector.OnPremises.ServiceMetadataUtility.RetrieveServiceEndpointMetadata(Type contractType, Uri serviceUri, Boolean checkForSecondary)
   at Microsoft.PowerPlatform.Dataverse.Client.Connector.OnPremises.ServiceConfiguration`1..ctor(Uri serviceUri, Boolean checkForSecondary)
   at Microsoft.PowerPlatform.Dataverse.Client.Connector.OnPremises.OrganizationServiceConfigurationAsync..ctor(Uri serviceUri, Boolean enableProxyTypes, Assembly assembly)
   at Microsoft.PowerPlatform.Dataverse.Client.Connector.OnPremises.ServiceConfigurationFactoryAsync.CreateManagement[TService](Uri serviceUri, Boolean enableProxyTypes, Assembly assembly)
   at Microsoft.PowerPlatform.Dataverse.Client.Auth.OnPremises_Auth.CreateAndAuthenticateProxy[T](IServiceManagement`1 servicecfg, Uri ServiceUri, Uri homeRealm, ClientCredentials userCredentials, String LogString, TimeSpan MaxConnectionTimeout, DataverseTraceLogger logSink)
   at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.ConnectAndInitServiceAsync(OrganizationDetail orgdata, Boolean IsOnPrem, Uri homeRealmUri)
   at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.DoDirectLoginAsync(Boolean IsOnPrem)
   at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.InitServiceAsync()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.GetCachedService(ConnectionService& ConnectionObject)
   at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.IntilizeService(ConnectionService& ConnectionObject)
   at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.CreateServiceConnection(Object externalOrgServiceProxy, AuthenticationType requestedAuthType, String hostName, String port, String orgName, NetworkCredential credential, String userId, SecureString password, String domain, String Geo, String claimsHomeRealm, Boolean useSsl, Boolean useUniqueInstance, OrganizationDetail orgDetail, String clientId, Uri redirectUri, PromptBehavior promptBehavior, OrganizationWebProxyClientAsync externalOrgWebProxyClient, String certificateThumbPrint, StoreName certificateStoreName, X509Certificate2 certificate, Uri instanceUrl, Boolean isCloned, Boolean useDefaultCreds, Version incomingOrgVersion, ILogger externalLogger, String tokenCacheStorePath)
   --- End of inner exception stack trace ---
   at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.CreateServiceConnection(Object externalOrgServiceProxy, AuthenticationType requestedAuthType, String hostName, String port, String orgName, NetworkCredential credential, String userId, SecureString password, String domain, String Geo, String claimsHomeRealm, Boolean useSsl, Boolean useUniqueInstance, OrganizationDetail orgDetail, String clientId, Uri redirectUri, PromptBehavior promptBehavior, OrganizationWebProxyClientAsync externalOrgWebProxyClient, String certificateThumbPrint, StoreName certificateStoreName, X509Certificate2 certificate, Uri instanceUrl, Boolean isCloned, Boolean useDefaultCreds, Version incomingOrgVersion, ILogger externalLogger, String tokenCacheStorePath)
   at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.ConnectToService(String connectionString, ILogger logger)
   at PowerPlatform.Dataverse.CodeSamples.Program.Main(String[] args) in C:\Users\maxap\source\repos\Tests\Dynamics365\Dynamics365Test3\Dynamics365Test3\Program.cs:line 48*

Что в данном случае означает это исключение? И как можно подключиться к Dynamics 365 в описанной ситуации?


Ответы (0 шт):