1

I'm creating client side Blazor app with Microsoft.OData.Client. When I create new entity like this:

            var dataServiceContext = this.ClientFactory.CreateClient<Container>(new Uri("http://localhost:5000/odata"));
            var newAsset = new CreateAssetDto()
            {
                TechnicalName = "from_client_4",
                DisplayNameFormat = "format from client",
                Icon = "client/icon",
                InheritedFrom = Guid.NewGuid(),
                IsActive = true,
                Translation = new AssetTranslationDto
                {
                    Title = "Client Asset",
                    Language = "en",
                    Description = "This is asset from client"
                }
            };

            dataServiceContext.AddToAssets(newAsset);
            await dataServiceContext.SaveChangesAsync();

I get an exception stating that response to this POST request is missing Location header. When I run fiddle to see what's going on I can see that it actually made 2 requests.enter image description here

The first request is POST but doesn't include the body and recieves 204 response. The second request is the one that actually contains the data creating new Asset and response contains Location header as it should.

I guess OData Client is complaining about Location header missing in the response for the first request (since response for second request does contain the header). But why is it even making the first request?

Any idea how to deal with this problem?

1 Answers1

0

It's possible that the first request is a preflight request sent by the browser. But normally CORS preflight requests are sent using OPTIONS method, not POST. So this case is curious.

I am a contributor to the project but do not have enough reputation to add comments here to get clarifications. Could you create an issue on https://github.com/OData/odata.net ?

habbes
  • 66
  • 2
  • You are right. It actually was OPTIONS request not POST. My bad. But anyway it does not solve my problem. And one more thing, I'm using ODataClient version 7.6.4 because there are some breaking changes from version 7.7.0 that don't work with client side blazor – Daniel Glos Nov 12 '20 at 08:50
  • I created the issue https://github.com/OData/odata.net/issues/1927 – Daniel Glos Nov 12 '20 at 09:06