提供的OData服务文档基本URL中的WebAPI的OData一个斜线 [英] Give OData service document base URL a trailing slash in WebApi OData
问题描述
我如何控制基础URL属性在OData服务文档的根元素?
How can I control the base URL attribute in the root element of an OData service document?
我设置使用的WebAPI,在<一个OData服务href=\"http://msdn.microsoft.com/en-us/library/system.web.http.odata.builder.odataconventionmodelbuilder%28v=vs.111%29.aspx\"><$c$c>System.Web.Http.OData.Builder.ODataConventionModelBuilder$c$c>和控制器从<一个继承href=\"http://msdn.microsoft.com/en-us/library/system.web.http.odata.odatacontroller%28v=vs.111%29.aspx\"><$c$c>System.Web.Http.OData.ODataController$c$c>
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
这一切精美的作品和Excel 2013愉快地访问数据。
It all works beautifully and Excel 2013 happily accesses the data.
问题尝试使用Excel 2010和PowerPivot的出现时。我知道了JSON格式的响应修复的在没有接受头部被发送,但我无法找到与基本URL问题的任何讨论。
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.
我已经建立了我的ODATA路线与 config.Routes.MapODataRoute(ODATA,ODATA,builder.GetEdmModel());
和我打这个时网址我得到℃的响应;服务XML:基地=HTTP://本地主机/ ODATA的xmlns =http://www.w3.org/2007/app的xmlns:原子= http://www.w3.org/2005/Atom/&GT;
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 +读取此URL,并决定,因为在基础URI上没有尾随斜线,应该要求与集合的URI的根,例如的http://本地主机/产品
而不是的http://本地主机/ ODATA /产品
,因为它应该
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.
我已经访问服务文件的静态版本,修改结尾的斜线添加到基证实了我的怀疑属性值,然后正确的URL请求的收集资源。
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.
我试图通过ASP.Net WebStack源$ C $ C工作,看看我是否可以覆盖格式化或东西,但迷路了。任何建议将不胜AP preciated。
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.
推荐答案
我和PowerPivot的同样的问题,我设法修复XML:基地与之兼容。这里需要code部分:
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);
}
}
和
config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel(), new MyODataPathHandler(), ODataRoutingConventions.CreateDefault());
自定义ODataPathHandler会增加额外的斜杠的默认路径,这将导致一个xml:基地周围PowerPivot中的bug工作。第二个问题是在PowerPivot的XML数据的预期,而不是JSON。 //aspnetwebstack.$c$cplex.com/workitem:对于一个解决方法可以在 HTTP找到/ 820
这篇关于提供的OData服务文档基本URL中的WebAPI的OData一个斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!