locked
OData $batch from Postman RRS feed

  • Question

  • User1403617900 posted

    I am trying to post OData batch request in postman.
    I am using Postman to query on ASP.net Web API with OData version 4.

    The url:

    http://localhost:52484/$batch

    Header:

    Content-Type : multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b

    Body (raw) :

    --batch_36522ad7-fc75-4b56-8c71-56071383e77b
    Content-Type: application/http
    Content-Transfer-Encoding:binary

    GET /Schools?$top=1
    Host: host

    --batch_36522ad7-fc75-4b56-8c71-56071383e77b

    But am getting the below error:

    {
    "Message": "No HTTP resource was found that matches the request URI 'http://localhost:52484/%24batch'.",
    "MessageDetail": "No route providing a controller name was found to match request URI 'http://localhost:52484/%24batch'"
    }

    Any idea about what is missing in the request?

    Thursday, October 10, 2019 7:36 AM

All replies

  • User61956409 posted

    Hi Anandam,

    No route providing a controller name was found to match request URI 'http://localhost:52484/%24batch'

    Please check if you configure OData route and batchHandler correctly, the following work for me, please refer to it.

    ODataBatchHandler odataBatchHandler = new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer);
    odataBatchHandler.MessageQuotas.MaxOperationsPerChangeset = 10;
    odataBatchHandler.MessageQuotas.MaxPartsPerBatch = 10;
    
    config.MapODataServiceRoute(
        routeName: "ODataRoute",
        routePrefix: null,
        model: builder.GetEdmModel(),
        batchHandler: odataBatchHandler
        );

    With Regards,

    Fei Han

    Friday, October 11, 2019 6:22 AM
  • User1403617900 posted

    Hi Fei Han.

    Thank you for that prompt answer! :)

    It does fix that issue but now am getting another error:

    "The request line 'GET /Schools?$top=1' is invalid. The request line at the start of each operation must be of the format 'HttpMethod RequestUrl HttpVersion'."

    Please note, I am sending post request to 'http://localhost:52484/$batch'

    Friday, October 11, 2019 9:08 AM
  • User61956409 posted

    Hi Anandam,

    "The request line 'GET /Schools?$top=1' is invalid. The request line at the start of each operation must be of the format 'HttpMethod RequestUrl HttpVersion'."

    You can try to specify HttpVersion

    GET /Schools?$top=1 HTTP/1.1

    Besides, you can refer to example in following link to execute batch operations.

    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/execute-batch-operations-using-web-api#example

    With Regards,

    Fei Han

    Friday, October 11, 2019 9:21 AM
  • User1403617900 posted

    Hi Fei Han.

    I tried that, still I am missing something.


    The controller:

    public class SchoolsController : ODataController
    {
    private readonly ISchoolService _schoolService;
    public SchoolsController(ISchoolService schoolService)
    {
    _schoolService = schoolService;
    }

    [EnableQuery(PageSize = 10,MaxExpansionDepth= 12,MaxAnyAllExpressionDepth = 5)]
    public IQueryable<School> Get()
    {
    return _schoolService.Schools();
    }

    [HttpGet]
    [EnableQuery]
    public IQueryable<School> Schools()
    {
    return _schoolService.Schools();
    }
    }


    Request:

    --batch_36522ad7-fc75-4b56-8c71-56071383e77b
    Content-Type: application/http
    Content-Transfer-Encoding:binary

    GET /Schools?$top=1 HTTP/1.1
    Host: host

    --batch_36522ad7-fc75-4b56-8c71-56071383e77b

    Error:

    "An error occurred when trying to create a controller of type 'SchoolsController'. Make sure that the controller has a parameterless public constructor."

    Friday, October 11, 2019 9:35 AM
  • User1403617900 posted

    I got rid of the above error by adding
    GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
    to the method
    CreateKernel()
    But now getting
    The method or operation is not implemented.

    Saturday, October 12, 2019 9:50 AM
  • User61956409 posted

    Hi Anandam,

    If you can provide a reproducible sample, we can help check and troubleshoot the issue better.

    With Regards,

    Fei Han

    Thursday, October 17, 2019 2:34 AM