调用 RetrieveOrganizationInfoRequest 时出现 NetDispatcherFaultException

NetDispatcherFaultException while calling RetrieveOrganizationInfoRequest

我正在尝试调用 RetrieveOrganizationInfoRequest。问题是我在最新的 SDK (Install-Package Microsoft.CrmSdk.CoreAssemblies -Version 9.0.2.5) 中找不到它 - 它存在于 9.0.2.4 SDK 中并且仍然受 CRM 支持。

有一种已知方法可以解决这个问题(我的意思是除了降级 SDK 之外)- 明确执行请求。即:

using (var serviceProxy = new OrganizationServiceProxy(new Uri(org.OrganizationServiceUri),
           null, credentials, null))
{
   serviceProxy.Timeout = new TimeSpan(0, 10, 0);
   var response = os.Execute(new OrganizationRequest("RetrieveOrganizationInfo"));
}

这有效 - 从某种意义上说,CRM returns 响应,但客户端无法反序列化它:

System.ServiceModel.Dispatcher.NetDispatcherFaultException
HResult=0x80131501 Message=The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:ExecuteResult. The InnerException message was 'Error in line 1 position 1400. Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'http://schemas.microsoft.com/xrm/9.0/Contracts:OrganizationInfo'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'OrganizationInfo' and namespace 'http://schemas.microsoft.com/xrm/9.0/Contracts'.'. Please see InnerException for more details.

我想我以某种方式缺少类型映射。我尝试用我自己的

替换 DataContractResolver
var contract = serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Contract;
var operation = contract.Operations.Find("Execute");
var behavior = operation.Behaviors.Find<DataContractSerializerOperationBehavior>();

behavior.DataContractResolver = new CustomDataContractResolver();

但是 CustomDataContractResolver 没有被调用。有没有想过如何连接合同处理以便可以覆盖此行为?

我不久前用一个早期的 v9.0 Microsoft.CrmSdk.CoreAssemblies NuGet 包测试了 RetrieveOrganizationInfoRequest 消息。

当我看到你的问题时,我启动了那个解决方案并 运行 它。它 运行 很好。

然后我将所有 NuGet 包更新到最新版本(IdentityModel 除外)。这将 CoreAssemblies 包带到了 v9.0.2.5。 以下是全部更新后的 NuGet 包:

这使得该消息停止工作,因为它不再出现在 Microsoft.Crm.Sdk.Messages 命名空间中。

虽然它似乎没有被很好地记录(或根本没有),RetrieveCurrentOrganizationRequest message may have superseded it, along with the RetrieveCurrentOrganizationResponse 消息。

我对此进行了测试,它适用于 v9.0.2.5 核心程序集。

另外...我通常直接使用请求 类,而不是使用名称参数实例化 OrganizationRequest。您的构造函数示例:
new OrganizationRequest("RetrieveOrganizationInfo")
似乎不是有效的请求名称。当我使用你的语法时,我得到了和你一样的错误。
当我尝试它时:
new OrganizationRequest("RetrieveOrganizationInfoRequest");
我得到了一个不同的错误:

此外,我赞扬您编写自己的解析器的勇气。幸运的是,从 D365 获得支持的响应永远不会那么复杂。

误删,已在最新的Xrm Sdk中修复。

Install-Package Microsoft.CrmSdk.CoreAssemblies -Version 9.0.2.12

// using Microsoft.Crm.Sdk.Messages from assembly Microsoft.Crm.Sdk.Proxy
var response = (RetrieveOrganizationInfoResponse)os.Execute(new RetrieveOrganizationInfoRequest());