I'm trying to invoke RetrieveOrganizationInfoRequest. Problem is I can't find it in latest SDK (Install-Package Microsoft.CrmSdk.CoreAssemblies -Version 9.0.2.5
) - it existed in 9.0.2.4
SDK and is still supported by CRM.
There is a known way how to get around this (I mean other than downgrading SDK) - execute the request explicitly. I.E.:
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"));
}
This works - in a sense that CRM returns response, but client fails to deserialize it with:
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.
I guess I'm missing the type mapping somehow. I tried to replace the DataContractResolver
with my own like
var contract = serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Contract;
var operation = contract.Operations.Find("Execute");
var behavior = operation.Behaviors.Find<DataContractSerializerOperationBehavior>();
behavior.DataContractResolver = new CustomDataContractResolver();
But the CustomDataContractResolver
is not getting invoked. Any thoughts how to hook up on contract handling so this behavior can be overriden ?
I had tested the RetrieveOrganizationInfoRequest
message a while back with an earlier v9.0 Microsoft.CrmSdk.CoreAssemblies NuGet package.
When I saw your question I fired up that solution and ran it. It ran fine.
Then I updated the all the NuGet packages to the latest version (except IdentityModel). This brought the CoreAssemblies package to v9.0.2.5. Here are the NuGet packages after updating all :
This made that message stop working, as it is no longer found in the Microsoft.Crm.Sdk.Messages
namespace.
Though it does not appear to be documented well (or at all), the RetrieveCurrentOrganizationRequest message may have superseded it, along with the RetrieveCurrentOrganizationResponse message.
I tested that and it works with the v9.0.2.5 core assembly.
Also... I typically use the request classes directly rather than instantiating OrganizationRequest with a name parameter. Your constructor example:
new OrganizationRequest("RetrieveOrganizationInfo")
does not seem to be a valid request name. When I used your syntax I got the same error as you.
When I tried it as:
new OrganizationRequest("RetrieveOrganizationInfoRequest");
I got a different error:
Also, I commend your boldness in writing your own resolver. Fortunately, getting a supported response from D365 should never be that complex.
It was removed by mistake and is fixed in latest 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());
User contributions licensed under CC BY-SA 3.0