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