OData v4 function always returns 404

Trying to migrate from OData v3 to OData v4 . Why am I trying to use 404 when I try to use the OData functions strong>?

Web API Configuration:

ODataModelBuilder builder = new ODataConventionModelBuilder(); //etc builder.EntitySet<LocalizableString>("LocalizableStringApi"); //etc var getComparitiveTableFunction = builder.EntityType<LocalizableString>().Collection.Function("GetComparitiveTable"); getComparitiveTableFunction.Parameter<string>("cultureCode"); getComparitiveTableFunction.ReturnsCollection<ComparitiveLocalizableString>(); //etc config.MapODataServiceRoute("OData_Kore_CMS", "odata/kore/cms", builder.GetEdmModel()); 

C # code:

 [EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)] [HttpGet] //[ODataRoute("Default.GetComparitiveTable(cultureCode={cultureCode})")] // Tried this, but gets errors and I noticed the function is in the OData model anyway without this, so should be fine. public virtual IHttpActionResult GetComparitiveTable([FromODataUri] string cultureCode) { // Implementation return Ok(query); } 

XML Return from Metadata:

 <Schema Namespace="Default"> <Function Name="GetComparitiveTable" IsBound="true"> <Parameter Name="bindingParameter" Type="Collection(Kore.Localization.Domain.LocalizableString)"/> <Parameter Name="cultureCode" Type="Edm.String" Unicode="false"/> <ReturnType Type="Collection(Kore.Localization.Models.ComparitiveLocalizableString)"/> </Function> ... 

As you can see, this is in the schema of the / OData model ... but the following query does not work:

 http://localhost:30863/odata/kore/cms/LocalizableStringApi/Default.GetComparitiveTable(cultureCode='en-US') 

I also tried the following:

 http://localhost:30863/odata/kore/cms/LocalizableStringApi/GetComparitiveTable(cultureCode='en-US') http://localhost:30863/odata/kore/cms/Default.GetComparitiveTable(cultureCode='en-US') http://localhost:30863/odata/kore/cms/GetComparitiveTable(cultureCode='en-US') 

All of the above leads to 404 .

So ... what am I doing wrong here?

+5
source share
4 answers

I solved this by adding the following line to my web.config , under <system.webServer> :

 <modules runAllManagedModulesForAllRequests="true"> 

This can cause performance issues if I remember correctly. So this is not perfect. Any best solutions are greatly appreciated ...

+4
source

I am solving a similar problem by adding a trailing slash to the requested URL.

+11
source

To work with IIS, you need a module called UrlRoutingModule-4.0. This solution forces all registered HTTP modules to run each request, not just managed requests (e.g. .aspx). This means that the modules will always work .jpg.gif.css.html.pdf, etc.

So, the best solution would be to add the following to web.config

 <modules> <remove name="UrlRoutingModule-4.0" /> <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> </modules> 

Source: http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html

+3
source

This is a solution to prevent 404 Not Found error with OData functions / actions.

Benefits of this solution

Add line abstracts to web.config

 <system.webServer> <handlers> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0Custom" path="/odata*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer> 

Et Voilà :)

+1
source

All Articles