Mark T
Mark T

Reputation: 190

FaultException when using ExecuteTransactionRequest (CRM 2015)

I'm doing a bit of a technical investigation into the ExecuteTransactionRequest. It's not something I've ever used before so I knocked up a very quick experiment just to see how it works. However, when sending off the request the OrganizationService is throwing back a FaultException (below). What I believe is happening is that my version of CRM doesn't support that OrganizationRequest. Although I'm pretty sure I have the right assemblies and version.

Can anyone please shed some light on what I'm missing?

CRM Deployment Version: 7.0.1.129

Organization Version: 7.0.2.53

Microsoft.Xrm Assembly Version: 7.0.0.0 (Also happened with 8.0.0.0)

An unhandled exception of type 'System.ServiceModel.FaultException' occurred in Microsoft.Xrm.Sdk.dll

Additional information: 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:request. The InnerException message was 'Error in line 1 position 451. Element 'http://schemas.microsoft.com/xrm/2011/Contracts/Services:request' contains data from a type that maps to the name 'http://schemas.microsoft.com/xrm/2011/Contracts:ExecuteTransactionRequest'. 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 'ExecuteTransactionRequest' and namespace 'http://schemas.microsoft.com/xrm/2011/Contracts'.'. Please see InnerException for more details.

CrmConnection connection = CrmConnection.Parse(GetCrmConnectionString("unmanaged"));
IOrganizationService orgService = new OrganizationService(connection);

ExecuteTransactionRequest transactionRequest = new ExecuteTransactionRequest()
{
    ReturnResponses = true,
    Requests = new OrganizationRequestCollection()
};

Entity newContact = new Entity("contact");
newContact["firstname"] = "Stack";
newContact["lastname"] = "Overflow";

CreateRequest createRequest = new CreateRequest()
{
    Target = newContact
};

transactionRequest.Requests.Add(createRequest);

ExecuteTransactionResponse transactionResponse = (ExecuteTransactionResponse)orgService.Execute(transactionRequest);

Upvotes: 1

Views: 881

Answers (1)

dynamicallyCRM
dynamicallyCRM

Reputation: 2980

Update

Quick look at your code, looked like it was because of the CreateRequest not being added to the collection. After your comments and double checking the crm organization version, you are on CRM 2015 (not on update 1). ExecuteTransactionRequest is only supported by CRM 2015 update 1 (version 7.1.XXX) and up (version 8.0.XXX) organizations. So unfortunately, your query won't work until at least the 2015 update is applied to the organization.


You did not add your create request to the ExecuteTransactionRequest - Requests collection. An empty request collection is causing the exceptions most likely.

ExecuteTransactionRequest transactionRequest = new ExecuteTransactionRequest()
{
     ReturnResponses = true,
     Requests = new OrganizationRequestCollection()
};

Entity newContact = new Entity("contact");
newContact["firstname"] = "Stack";
newContact["lastname"] = "Overflow";

CreateRequest createRequest = new CreateRequest()
{
     Target = newContact
};

transactionRequest.Requests.Add(createRequest); //missing

ExecuteTransactionResponse transactionResponse = (ExecuteTransactionResponse)orgService.Execute(transactionRequest);

Upvotes: 1

Related Questions