Chiricescu Mihai Chiricescu Mihai - 4 months ago 15
C# Question

Odata with no metadata actions not working

I tried the solution described in this article here:
Original article

As described i did:

var defaultConventions = ODataRoutingConventions.CreateDefault();
var conventions = defaultConventions.Except(
defaultConventions.OfType<MetadataRoutingConvention>());
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: null,
model: model,
pathHandler: new DefaultODataPathHandler(),
routingConventions: conventions);


Everything worked ok, no more metadata informations. Standard request work Ok but the unbound actions and functions are not working anymore i get a 404 response.

I register actions to Odata model builder like:

var validateEmailAction = builder.Action("ValidateEmail");
validateEmailAction.Parameter<string>("Email");


And in controller i have:

[HttpPost]
[ODataRoute("ValidateEmail")]
public async Task<IHttpActionResult> ValidateEmail(ODataActionParameters parameters)
{
}


Any suggestions how can i achieve hiding Odatametada but still have actions/functions working?

Answer

ODataRoutingConventions.CreateDefault()

will create a list of routing conventions WITHOUT attribute routing.

While, unbound actions and functions need attribute routing.

So, You must change to call:

ODataRoutingConventions.CreateDefaultWithAttributeRouting();
Comments