Give OData service document base URL a trailing slash in WebApi OData

前端 未结 1 1033
独厮守ぢ
独厮守ぢ 2021-01-13 06:33

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.B

相关标签:
1条回答
  • 2021-01-13 07:01

    I had the same problem with PowerPivot and I managed to fix the xml:base to be compatible with it. Here's the part of the code needed:

    class MyODataPathHandler : DefaultODataPathHandler
    {
        public override string Link(ODataPath path)
        {
            if (path.PathTemplate == "~")
            {
                return path.ToString() + "/";
            }
            return base.Link(path);
        }
    }
    

    and

    config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel(), new MyODataPathHandler(), ODataRoutingConventions.CreateDefault());
    

    the custom ODataPathHandler will add the extra slash for the default path, which results in an xml:base that works around the bug in PowerPivot. The second issue is PowerPivot expects data in XML, not in JSON. One workaround for that can be found at http://aspnetwebstack.codeplex.com/workitem/820

    0 讨论(0)
提交回复
热议问题