动力学365:为什么我得到“ Xrm.sdk wsdl” .NET6控制台客户端的错误?

发布于 2025-01-30 04:05:57 字数 2961 浏览 1 评论 0原文

Mac OS,.NET6,C#10.0。

我总是在.NET Framework平台上为MS Dynamics 365创建控制台客户端,没有问题。但是现在,我需要在.NET Core或更新的平台上进行相同的操作(因为稍后需要将其放入Docker容器中)。在这种情况下,我尝试使用.net6。

我创建了新的控制台应用程序,并添加了Nuget软件包:

  • Microsoft.poperplatform.datavers.client v0.6.6
  • system.configuration.configurationmanager v6.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.servicemodel
  • 。 pirinives v4.9.0

我的简单program.cs文件:

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();
        }
    }
}

但是当我运行应用程序时,我会得到错误:

xrm.sdk wsdl

为什么会发生以及如何解决?

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(
quot;\nOrganizationService: {orgServiceUrl}");
                    Console.WriteLine(
quot;CRM version: {versionResponse.Version}");
                    Console.WriteLine(
quot;User login: {crmUserLogin}");

                    Console.WriteLine(
quot;\nOrganizationId: {whoAmIResponse.OrganizationId}");
                    Console.WriteLine(
quot;BusinessUnitId: {whoAmIResponse.BusinessUnitId}");
                    Console.WriteLine(
quot;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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

西瓜 2025-02-06 04:05:57

组织服务客户端被弃用,不直接支持网络核心。

使用DataVerse ServiceClient连接时,连接字符串或ServiceClient构造器是唯一支持的方法。

也就是说,由于基础身份验证堆栈的变化,ONPREM并没有得到很好的支持。

当前最好的支持功能是通过PREM上的ADF和自定义验证处理程序使用OAuth。

Dataverse Service客户端的用户编写了一个扩展名,它添加了对Net Core的AD和WSTRUST支持,但它不是MS分布的一部分。

您可以在Dataverse ServiceClient GitHub站点问题委员会板上找到指向它的链接
https://github.com/github.com/microsoft/microsoft/microsoft/microsoft/poperplatform-dataaverform-dataaverform-dataaverform-dataaverform-dataaverform-dataaverforf >

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

人间☆小暴躁 2025-02-06 04:05:57

如果可能的话,使用Dataverse Service客户端连接到.NET 6的本地实例。如果要使用连接字符串连接:

  1. 必须配置IFD。
  2. 您必须拥有ADFS 2019。
  3. 您必须使用OAuth,
  4. 必须在ADF上创建的客户端应用程序
  5. 作为写作时间,DVSC中有一个错误,您可能需要其他配置。

如果您使用custom tokenProviderFunction使用ADFS 2016,也有可能连接。

配置非常冗长,但在本文中详细撰写:使用Dataverse Service Client连接到OnPrem Dynamics 365 CRM(来自.net 6+)以及代码示例

Connecting to on-premises instance from .NET 6 using Dataverse Service Client if possible. If you want to connect using connection string:

  1. You must have IFD configured.
  2. You must have ADFS 2019.
  3. You must use OAuth
  4. You must have client application created at ADFS
  5. As time of writing, there is a bug in DVSC and you may need additional configuration.

There is also possibility to connect if you are using ADFS 2016 using custom tokenProviderFunction.

Configuration is quite lengthy but written in detail at this article: Using Dataverse Service Client to connect to OnPrem Dynamics 365 CRM (From .NET 6+) along with code examples on github.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文