Dynamics 365: why I get "Xrm.Sdk WSDL" error for .net6 console client?

Viewed 209

Mac OS, .Net6, C# 10.0.

I always created console clients for MS Dynamics 365 on .Net Framework Platform without problems. But now I need to do the same on .Net Core or newer platform (because I need to put it into Docker container later). At this case I try to use .Net6.

I created new console application and added the NuGet packages:

  • Microsoft.PowerPlatform.Dataverse.Client v0.6.6
  • System.Configuration.ConfigurationManager v6.0.0
  • System.ServiceModel.Primitives v4.9.0

My simple Program.cs file:

using System.Net;
using System.ServiceModel.Description;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Client;

namespace ConsoleAppExample
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "CRM console client";

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var orgServiceUrl = "http://dev-crm-app02/MyCompany/XRMServices/2011/Organization.svc";
            var crmUserLogin = "myLogin";
            var crmUserPassword = "myPassword"; 

            var credentials = new ClientCredentials();
            credentials.UserName.UserName = crmUserLogin;
            credentials.UserName.Password = crmUserPassword;

            try
            {
                using (var orgService = new OrganizationServiceProxy(new Uri(orgServiceUrl),
                           null, credentials, null))
                {
                    RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
                    RetrieveVersionResponse versionResponse =
                        (RetrieveVersionResponse) orgService.Execute(versionRequest);

                    WhoAmIRequest whoAmIRequest = new WhoAmIRequest();
                    WhoAmIResponse whoAmIResponse = (WhoAmIResponse) orgService.Execute(whoAmIRequest);

                    Console.WriteLine($"\nOrganizationService: {orgServiceUrl}");
                    Console.WriteLine($"CRM version: {versionResponse.Version}");
                    Console.WriteLine($"User login: {crmUserLogin}");

                    Console.WriteLine($"\nOrganizationId: {whoAmIResponse.OrganizationId}");
                    Console.WriteLine($"BusinessUnitId: {whoAmIResponse.BusinessUnitId}");
                    Console.WriteLine($"UserId: {whoAmIResponse.UserId}");
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message); // Xrm.Sdk WSDL
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }

                Console.ResetColor();
            }
            Console.WriteLine("\nPress ENTER for exit...");
            Console.ReadLine();
        }
    }
}

But when I run my application I get the error:

Xrm.Sdk WSDL

Why does it happen and how can I solve it?

1 Answers

Organization service client is deprecated and is not supported directly on net core.

When connecting using the dataverse serviceclient, connection string or serviceclient constructor is the only supported way.

That said onprem is not well supported due to the changes I the underlying authentication stack.

Best currently possible supported feature is to use oAuth via adfs on prem with a custom auth handler.

There is an extension written by a user of the dataverse service client that adds AD and WSTrust support for net core, but it is not part of the MS distribution.

You can find a link to it on the dataverse serviceclient GitHub site issues board under the AD onPrem support topic https://github.com/microsoft/PowerPlatform-DataverseServiceClient/issues/110

Related