Ws-Trust 身份验证已被弃用并且在您的环境中不再受支持。请使用oAuth2.0认证

Ws-Trust authentication which has been deprecated and no longer supported in your environment. Please use oAuth2.0 authentication

在当前项目中,我使用此语法从 Dynamic CRM 检索数据:

using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, null, _crmCredentials, null)
{
    // Creating IOrganizationService object to access organization services
    IOrganizationService service = serviceProxy;
    EntityCollection retrieveAccountGuid = service.RetrieveMultiple(QueryOptions);

    return retrieveAccountGuid;
}

任何人都可以帮助我我需要做哪些改变?

我已阅读这篇文章,但如何在代码中替换 IOrganizationService

https://docs.microsoft.com/en-us/power-apps/developer/data-platform/authenticate-office365-deprecation

CrmServiceClient 是我们可以用来连接到 .NET 中的 Dynamics 365 的 class。它支持多种身份验证方案。对于 Azure 和 Power Platform 上的 server-to-server 通信,使用应用程序注册是推荐的方法。

访问 Dynamics/Dataverse 的应用程序注册需要添加为应用程序用户,并且必须分配适当的安全角色。另见 Register an app with Azure Active Directory - MS Docs

CrmServiceClient 实现了 IOrganizationService 接口,因此您的大部分代码应该以相同的方式工作。只需用这样的东西替换 OrganizationServiceProxy 的实例:

private void Test(Uri dataverseUrl, Guid clientId, string clientSecret, string tokenCachePath)
{
    using (var client = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(dataverseUrl, clientId.ToString("D"), clientSecret, false, tokenCachePath))
    {
        Perform(client);
    }
}

private void Perform(IOrganizationService organizationService)
{

}

CrmServiceClient 可以在 NuGet 包 Microsoft.CrmSdk.XrmTooling.CoreAssembly.

中找到
public CrmServiceClient devuelve_Servicio()
    {           
        CrmServiceClient svc = null;

        
        string ConnectionString = "AuthType = OAuth; " +
              "Username = ;" +
              "Password = ; " +
              "Url = https://.crm.dynamics.com;" +
              "AppId=;" +
              "RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;" +
              "LoginPrompt=Auto";
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        try
        {
            
            CrmServiceClient svc = new CrmServiceClient(ConnectionString);
            if (svc != null)
            {

                this.strErrMsg  = "Error en la conexión!!!" + "LastError: " + svc.LastCrmError.ToString();
               
               }
        }
        catch (Exception ex)
        {

            this.strErrMsg = ex.Message;
        }
        return svc;
    }
}