WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Unbound actions and functions are not called when custom routing is switched on

Open xpr0gamers opened this issue 4 years ago • 5 comments

  • A unbound function is implemented with an "ODataRoute" Attribute, for example "[ODataRoute("MigrateFirebaseToMssql")]"
  • In the startup.cs file, default routing conventions are created ("ODataRoutingConventions.CreateDefault()")
  • an odata service route is created with these default conventions ("oRouteBilder.MapODataServiceRoute("odata", "", GetEdmModel(), new DefaultODataPathHandler(), oConventions, new DefaultODataBatchHandler());") -after these lines, the unbound function with attribute routing not callable anymore

Actual result

404 Error Result

Reproduce steps

Startup.cs

       oApp.UseMvc(oRouteBilder =>
            {
                // Create the default collection of built-in conventions.
                var oConventions = ODataRoutingConventions.CreateDefault();
                oRouteBilder.SetTimeZoneInfo(TimeZoneInfo.Local);
                oRouteBilder.Select().Filter().Count().MaxTop(null).Expand().OrderBy();
                oRouteBilder.MapODataServiceRoute("odata", "", GetEdmModel(), new DefaultODataPathHandler(), oConventions, new DefaultODataBatchHandler());
                oRouteBilder.EnableDependencyInjection();
            });

UnboundFunctionController.cs

[HttpGet]
 [ODataRoute("MigrateFirebaseToMssql")]
 public async Task<IActionResult> MigrateFirebaseToMssqlAsync()
        {
            return Ok(true);
        }

xpr0gamers avatar Jan 12 '21 23:01 xpr0gamers

@xpr0gamers What code is in your "GetEdmModel"?

xuzhg avatar Jan 13 '21 00:01 xuzhg

@xpr0gamers How you doing.

CreateDefault defined here doesn't include attribute routing.

if you want to use the attribute routing, you can call the method defined here

xuzhg avatar Jan 19 '21 17:01 xuzhg

Thank you for your answer. With wich parameters, must i call the function? I get now an error. image image

xpr0gamers avatar Jan 27 '21 00:01 xpr0gamers

@xpr0gamers here's an example: https://github.com/OData/WebApi/blob/master/samples/AspNetCore3xEndpointSample.Web/Startup.cs#L64

xuzhg avatar Jan 27 '21 01:01 xuzhg

@xpr0gamers Were you able to resolve this issue?

KenitoInc avatar May 18 '22 11:05 KenitoInc

Closing this issue due to inactivity. If this issue still persists, feel free to create a new issue.

KenitoInc avatar Feb 13 '23 13:02 KenitoInc