Question

What specifically in WebAPI responds to:

1. http://server/vroot/odata  
2. http://server/vroot/odata?$metadata
3. http://server/vroot/odata/Foo

When #3 is requested, I understand that my 'FooController' responds as configured in my WebApiConfig.cs.

But it is not clear to me how WebAPI responds to #1 or #2. How does it know what to return? How is that response configured in my code?

UPDATE: Here is a HUGE clue

From http://blogs.msdn.com/b/webdev/archive/2013/01/29/getting-started-with-asp-net-webapi-odata-in-3-simple-steps.aspx

One important thing to realize here is that the controller name, the action names, and the parameter names all matter. OData controller and action selection work a little differently than they do in Web API. Instead of being based on route parameters, OData controller and action selection is based on the OData meaning of the request URI. So for example if you made a request for http://my.server.com/vroot/odata/$metadata, the request would actually get dispatched to a separate special controller that returns the metadata document for the OData service. Notice how the controller name also matches the entity set name we defined previously. I’ll try to go into more depth about OData routing in a future blog post. ]

Was it helpful?

Solution

  1. returns you the Service Document
  2. returns you the Service Metadata Document

WebAPI knows this because you add a route similar to config.Routes.MapODataRoute("ODataRoute", "odata", model);

Check out this detailed explanation: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/creating-an-odata-endpoint

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top