Chiricescu Mihai
Chiricescu Mihai

Reputation: 239

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?

Upvotes: 3

Views: 1346

Answers (2)

user2619288
user2619288

Reputation: 1

as mentioned above ,it works by using default with attribute routing but it also needs config and edm model attributes .

var edmModel = builder.GetEdmModel();
var defaultConventions  =ODataRoutingConventions.CreateDefaultWithAttributeRouting(config,edmModel);
var conventions = defaultConventions.Except(defaultConventions.OfType<MetadataRoutingConvention>());
        var route = config.MapODataServiceRoute(
            "odata",
            null,
           edmModel,
            pathHandler: new DefaultODataPathHandler(),
            routingConventions: conventions);

Upvotes: 0

Sam Xu
Sam Xu

Reputation: 3380

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();

Upvotes: 4

Related Questions