OData的V4函数总是返回404 [英] OData v4 Function always returns 404

查看:360
本文介绍了OData的V4函数总是返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图从的OData V3 移至的OData V4 。为什么我总是收到的 404 试图用时的OData功能

网络API配置:

  ODataModelBuilder建设者=新ODataConventionModelBuilder();
//等等
builder.EntitySet&所述; LocalizableString&GT(LocalizableStringApi);
//等等
VAR getComparitiveTableFunction = builder.EntityType< LocalizableString>()Collection.Function(GetComparitiveTable);
getComparitiveTableFunction.Parameter<串GT(文化code);
getComparitiveTableFunction.ReturnsCollection< ComparitiveLocalizableString>();
//等等
config.MapODataServiceRoute(OData_Kore_CMS,ODATA /科雷/ CMS,builder.GetEdmModel());

C#code:

  [EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)
[HTTPGET]
//[ODataRoute(\"Default.GetComparitiveTable(culture$c$c={culture$c$c}))] //想这一点,但得到的错误,我注意到的功能是在模型的OData反正没有这一点,所以应该罚款。
公共虚拟IHttpActionResult GetComparitiveTable([FromODataUri]串文化code)
{
    //实施
    返回OK(查询);
}

XML从$返回的元数据:

 <模式命名空间=默认>
    <作用NAME =GetComparitiveTable一个isBound =真>
        <参数名称=bindingParameterTYPE =集合(Kore.Localization.Domain.LocalizableString)/>
        <参数名称=文化codeTYPE =Edm.String统一code =FALSE/>
        <返回类型类型=集合(Kore.Localization.Models.ComparitiveLocalizableString)/>
    < /功能>
    ...

正如你所看到的,它在模式/模式OData的...但下面的查询不起作用:

<$p$p><$c$c>http://localhost:30863/odata/kore/cms/LocalizableStringApi/Default.GetComparitiveTable(culture$c$c='en-US')

我也试过如下:

<$p$p><$c$c>http://localhost:30863/odata/kore/cms/LocalizableStringApi/GetComparitiveTable(culture$c$c='en-US')
HTTP://本地主机:30863 / ODATA /科雷/ CMS / Default.GetComparitiveTable(文化code =EN-US)
HTTP://本地主机:30863 / ODATA /科雷/ CMS / GetComparitiveTable(文化code =EN-US)

以上所有的结果,在 404

所以...我究竟错在这里做什么?


解决方案

我解决了这个通过添加下面一行在我的的web.config ,在&LT; system.webServer&GT ;

 &LT;模块runAllManagedModulesForAllRequests =真正的&GT;

这可能会导致性能问题不过,如果我没有记错。因此,它不是理想的。任何更好的解决方案是非常欢迎...

Trying to move from OData v3 to OData v4. Why do I keep getting a 404 when trying to use OData Functions?

Web API Config:

ODataModelBuilder builder = new ODataConventionModelBuilder();
//etc
builder.EntitySet<LocalizableString>("LocalizableStringApi");
//etc
var getComparitiveTableFunction = builder.EntityType<LocalizableString>().Collection.Function("GetComparitiveTable");
getComparitiveTableFunction.Parameter<string>("cultureCode");
getComparitiveTableFunction.ReturnsCollection<ComparitiveLocalizableString>();
//etc
config.MapODataServiceRoute("OData_Kore_CMS", "odata/kore/cms", builder.GetEdmModel());

C# Code:

[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
[HttpGet]
//[ODataRoute("Default.GetComparitiveTable(cultureCode={cultureCode})")] // Tried this, but gets errors and I noticed the function is in the OData model anyway without this, so should be fine.
public virtual IHttpActionResult GetComparitiveTable([FromODataUri] string cultureCode)
{
    // Implementation
    return Ok(query);
}

XML Returned from $metadata:

<Schema Namespace="Default">
    <Function Name="GetComparitiveTable" IsBound="true">
        <Parameter Name="bindingParameter" Type="Collection(Kore.Localization.Domain.LocalizableString)"/>
        <Parameter Name="cultureCode" Type="Edm.String" Unicode="false"/>
        <ReturnType Type="Collection(Kore.Localization.Models.ComparitiveLocalizableString)"/>
    </Function>
    ...

As you can see, it's in the schema / OData model... yet the following query does not work:

http://localhost:30863/odata/kore/cms/LocalizableStringApi/Default.GetComparitiveTable(cultureCode='en-US')

I have also tried the following:

http://localhost:30863/odata/kore/cms/LocalizableStringApi/GetComparitiveTable(cultureCode='en-US')
http://localhost:30863/odata/kore/cms/Default.GetComparitiveTable(cultureCode='en-US')
http://localhost:30863/odata/kore/cms/GetComparitiveTable(cultureCode='en-US')

All of the above result in a 404.

So... what am I doing wrong here?

解决方案

I solved this by adding the following line in my web.config, under <system.webServer>:

<modules runAllManagedModulesForAllRequests="true">

This may cause performance issues though, if I remember correctly. So it's not ideal. Any better solutions are very welcome...

这篇关于OData的V4函数总是返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆