Does anyone know how to get OData v4 hosted in a .NET service to work with multiple routes?
I have the following:
config.MapODataServiceRoute("test1", "test1", GetEdmModelTest1()); config.MapODataServiceRoute("test2", "test2", GetEdmModelTest2());
Each of the GetEdmModel methods has associated objects.
I can access the service as follows (this works fine):
http://testing.com/test1/objects1 ()
http://testing.com/test2/objects2 ()
But if I try to call a function like the following (will not work):
[HttpGet] [ODataRoute("test1/TestFunction1()")] public int TestFunction1() { return 1; }
It produces the following error:
The path pattern 'test1 / TestFunction1 ()' in the action 'TestFunction1' in the controller 'Testing' is not a valid OData path pattern. Resource not found for segment 'test1'.
However, if I remove the "MapODataServiceRoute" for "test2", so there is only one route, it all works.
How do I get this to work with multiple routes?
** I posted a full example of the problem on the following **
https://github.com/OData/WebApi/issues/1223
** I tried the sample OData version below with the following problems **
https://github.com/OData/ODataSamples/tree/master/WebApi/v4/ODataVersioningSample
I tried the "OData Version" example before and it did not work. It seems that unbound (unbound is the target) does not follow the same routing rules as regular service calls.
Ex. If you download the OData Version example and follow these steps.
- In V1 -> WebApiConfig.cs add
builder.Function(nameof(Controller.ProductsV1Controller.Test)).Returns<string>(); - In V2 -> WebApiConfig.cs add
builder.Function(nameof(Controller.ProductsV2Controller.Test)).Returns<string>(); - In V1 -> Products V1Controller.cs add
[HttpGet] [ODataRoute("Test()")] public string Test() { return "V1_Test"; } - In V2 -> ProductsV2Controller.cs add
[HttpGet] [ODataRoute("Test()")] public string Test() { return "V2_Test"; }
Now call it. "/ versionbyroute / v1 / Test ()" and you will get "V2_Test"
The problem is that "GetControllerName" does not know how to get the controller when it uses unrelated functions / actions.
This is why most of the code examples that I discovered fail when trying to "output" the controller.