如何改变Dynamics Crm项目中WS-Trust的安全性?

问题描述 投票:0回答:1

我的情况是当我试图获取Organizationservice时,突然得到:Value cannot be null.Parameter name: service,经过查询,我发现我的proj使用了WS-Trust security,这可能会造成我的问题。

在阅读了ms docs后,我发现这可能是我的情况。

如果你正在访问CrmServiceClient.OrganizationServiceProxy属性。

在你的代码中删除所有对该属性的使用。CrmServiceClient实现了IOrganizationService,并公开了组织服务代理的所有可设置内容。

我的问题是,如果我删除了对.NET的使用,我可以用什么来替代?

 CrmServiceClient crmServiceClient = new CrmServiceClient( connectionString);
IOrganizationService organizationService = (IOrganizationService)crmServiceClient.OrganizationWebProxyClient != null
? (IOrganizationService)crmServiceClient.OrganizationWebProxyClient : (IOrganizationService)crmServiceClient.OrganizationServiceProxy;

什么可以被替换?

有人处理过这种情况吗?有其他方法解决吗?

authentication dynamics-crm dynamics-crm-2016
1个回答
0
投票

你眼前的问题可能是由于身份验证问题,比如密码过期。这将导致Service属性为空。你可以在使用返回的客户端之前查看LastCrmError属性,以便检测这种情况。我曾使用过这样的代码。

Microsoft.Xrm.Tooling.Connector.CrmServiceClient c = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connStr);

// At least when using Office365 authentication, invalid (or expired password) will show up in LastCrmError.
// I have not seen LastCrmException, but it sounds bad, too, to check that too.
if (!(string.IsNullOrEmpty(c.LastCrmError) && c.LastCrmException == null))
{
    Console.Error.WriteLine(Environment.NewLine + "CRM Error: " + c.LastCrmError);
    if (c.LastCrmException != null)
    {
        Console.Error.WriteLine("CRM Exception: " + c.LastCrmException.Message);
        Console.Error.WriteLine("CRM Exception details: " + c.LastCrmException.ToString());
    }
    Environment.Exit(99);
}

这段代码将 可能 停止工作,因为 WS-Trust 安全性被移除,并且您升级到较新的 9.2.x SDK,如在 使用WS-Trust安全协议的Office365认证。

我想通过只使用IOrganizationService接口中的方法(见下图)来对代码进行未来保护,但是CrmLastError在IOrganizationProxy接口中不可用,所以现在我使用上面的代码。但是其余的代码库只依赖于IOrganizationService接口,所以代码的重写应该是最小的。

IOrganizationService c = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connStr);
© www.soinside.com 2019 - 2024. All rights reserved.