How can I control the base URL attribute in the root element of an OData service document?
I'm setting up an OData service using WebApi, the System.Web.Http.OData.Builder.ODataConventionModelBuilder
and controllers inheriting from System.Web.Http.OData.ODataController
It all works beautifully and Excel 2013 happily accesses the data.
The problem arises when trying to use Excel 2010 and PowerPivot. I'm aware of the fix for JSON formatted responses being sent in the absence of an Accept header, but I can't find any discussion of problems with the base URL.
I have set up my odata route with config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());
and when I hit this URL I get a response of <service xml:base="http://localhost/odata" xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom"/>
Excel 2010 + PowerPivot reads this URL and decides that because there is no trailing slash on the base URI, it should request collections with URIs in the root, e.g. http://localhost/Products
instead of http://localhost/odata/Products
as it should.
I have confirmed my suspicion by accessing a static version of the service document, modified to add the trailing slash to the base attribute value and the correct URL is then requested for the collection resource.
I've tried working through the ASP.Net WebStack source code to see if I can override a formatter or something, but got lost. Any suggestions would be greatly appreciated.