OData / OData/AspNetCoreOData

POST $batch 200 --- but response is Not Found

Open
#705 14 comments 0 reactions 1 assignee View on GitHub

@xuzhg is already working on this.

Since Sep 27, 2022.

bug
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

ASP.NET Core OData 8.0.11

Hi, i have problem with batch request.
Request finished HTTP/1.1 POST http://localhost:5000/odata/$batch multipart/mixed;+boundary=batch_id-1664271614387-17 343 - 200 but the GET inside batch return > 404 Not Found

`
----------------------------------------------------------------------REQUEST-----------------------------------------------------------
--batch_id-1664271614387-17
Content-Type:application/http
Content-Transfer-Encoding:binary

GET Contracts(nrum='4104264',rokum='2021') HTTP/1.1
Accept:application/json;odata.metadata=minimal;IEEE754Compatible=true
Accept-Language:pl
Content-Type:application/json;charset=UTF-8;IEEE754Compatible=true

--------------------------------------------------------------------RESPOND----------------------------------------------------------
--batch_id-1664271614387-17--

--batchresponse_a336531a-38f4-4844-ba1e-f94afb0f2e73
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 404 Not Found

--batchresponse_a336531a-38f4-4844-ba1e-f94afb0f2e73--

`

I integrated odata with sap ui5...

from begining i have problem with CORS
to get rid of the error, I had to change the order in startup.cs
cors after Routing and Batch after CORS

app.UseRouting(); app.UseCors("AllowAllOrigins"); app.UseODataQueryRequest(); app.UseODataBatching(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); });

then i received problem with HEAD in bach request so i use my own Middleware
` app.UseMyOdataMiddleware();
app.Use((context, next) =>
{
context.Response.Headers["OData-Version"] = "4.0";
context.Response.Headers["OData-MaxVersion"] = "4.0";

            return next.Invoke();
        });

`

`public class HttpGetOrHeadAttribute : HttpMethodAttribute
{
private static readonly IEnumerable _supportedMethods = new[] { "GET", "HEAD" };

    public HttpGetOrHeadAttribute() : base(_supportedMethods) { }

    public HttpGetOrHeadAttribute(string template) : base(_supportedMethods, template)
    {
        if (template == null)
        {
            throw new ArgumentNullException(nameof(template));
        }
    }
}

public static class ODataMiddlewareExtensions
{
    public static IApplicationBuilder UseMyOdataMiddleware(this IApplicationBuilder builder)
    {
        return builder.UseMiddleware<ODataMiddleware>();
    }
} 

public class ODataMiddleware
{
    private readonly RequestDelegate _next;

    private readonly ILogger _logger;

    public ODataMiddleware(RequestDelegate next, ILoggerFactory logFactory)
    {
         _next = next ?? throw new ArgumentNullException(nameof(next));
        _logger = logFactory.CreateLogger("ODataMiddleware");
    }

    public async Task Invoke(HttpContext context)
    {
        _logger.LogInformation("ODataMiddlewaree executing..");

        
        bool methodSwitched = false;
 
        if (HttpMethods.IsHead(context.Request.Method))
        {
            methodSwitched = true;
           _logger.LogInformation("metoda:" +context.Request.Method);
            context.Request.Method = HttpMethods.Get;
            context.Response.Body = Stream.Null;
        }

        await _next(context);

        if (methodSwitched)
        {
            context.Request.Method = HttpMethods.Head;
        }
    }
}`

and finally when I have no mistakes, receives no answer

does anyone have any idea what could be wrong?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.