OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
677 stars 348 forks source link

Dynamics365 - The response to this POST request did not contain a 'location' header. That is not supported by this client. #1552

Open chigivigi opened 4 years ago

chigivigi commented 4 years ago

When performing Create action to my Dynamics CRM instance I get result without location header by Web API. As we cannot change MS Web API there is a problem when library crashes without location header.

Assemblies affected

We are using the the fallowing nuget packages: Microsoft.OData.Client v7.6.0, Microsoft.OData.Core v7.6.0, Microsoft.OData.Edm v7.6.0 and Microsoft.Spatial v7.6.0.

Reproduce steps

I have found two situations where the error happens.

One situation is when I create a new entity, contact for example:

  1. Create a new D365 contact
  2. Set the properties for the contact
  3. Add the contact to the DataServiceCollection
  4. set the following options in the CrmContext:

crmContext.EntityParameterSendOption = EntityParameterSendOption.SendOnlySetProperties; crmContext.AddAndUpdateResponsePreference = DataServiceResponsePreference.IncludeContent;

  1. Run the CrmContext SaveChanges method with the PostOnlySetProperties option

The other situation occurs when creating email activity with its activity parties:

  1. Create a new D365 email
  2. Set properties to the email
  3. Add the email to the DataServiceCollection
  4. Create a new D365 activity parties (Sender, Recipient)
  5. Assign activity parties to email (email_activity_parties property)
  6. Set properties to the activity parties
  7. Run the CrmContext SaveChanges method with the PostOnlySetProperties option

Expected result

Situation one: I expect when creating a new entity that I get the entity result information.

Situation two: I expect to have created email with sender and recipient set.

Actual result

Situation one: The code breaks when getting the response from Dynamics CRM because the response message does not contain the 'location' header.

Situation two: The email creation query passed successfully. The first activity party added to the email activity returns a 204 response with no 'location' header from MS CRM oData, blocking any further action queued in CrmContext. That leaves us with a created mail and only Sender field set.

Additional detail

We need a way to IgnoreLocationHeaderMissing error in a client because there are situation when we intentionally want to succeed without it so the response statusCode would be taken for decision; we are not in a position to change the oData server and way it responds.

Another thing which would be nice to have and know how to do is a nested create. Crm oData supports creating all three entities in one query but the json of activity parties should be incorporated into email body. How can we achieve this with the library because it automatically builds 3 queries. We tried with batch single change set but that is a different thing.

xuzhg commented 4 years ago

Did you check it with Dynamics server?

From Web API OData, it sets the location header in the Created response. See https://github.com/OData/WebApi/blob/master/src/Microsoft.AspNet.OData/Results/CreatedODataResult.cs#L129

dominicusmento commented 4 years ago

@xuzhg thanks for your response. I have the same problem and yes, usually it returnes location header. The problem is when Contained Entity is created. Then it doesn't contain a location header. I tried to point that out to Microsoft but they said that this is considered bug (probably ultra-low priority - because they recommend deep insert by documentation) and it won't be implemented soon. That's why ignorance of the missing header would be nice addition to the library. I can post the javascript example if needed where it is clearly visible that location header is missing. OData-EntityId header when 204 is returned is missing too but that's probably another story.

Myster commented 3 years ago

I have this issue also