网页API 2:4 OData的:操作返回404 [英] Web API 2: OData 4: Actions returning 404
问题描述
我有一个的OData V4
操作方法,它不能正常工作;不过要注意的是在的OData V3
工作正常(我明明在尝试更新我的项目过程中)
I have an OData v4
action method which is not working; note however that it was working fine in OData v3
(I am obviously in the process of trying to update my project)
OData的行动方式:
[HttpPost]
public Translation Translate(ODataActionParameters parameters)
{
// Implementation
}
配置:
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Page>("Pages");
//etc (Other Entity Sets)
var pageEntityType = builder.EntityType<Page>();
var translateAction = pageEntityType.Collection.Action("Translate");
translateAction.Parameter<Guid>("pageId");
translateAction.Parameter<string>("cultureCode");
translateAction.Returns<Translation>();
//etc (Other Actions)
var route = config.MapODataServiceRoute("OData_CMS", "odata/cms", builder.GetEdmModel());
客户端AJAX调用:
var data = {
pageId: $("#CultureSelector_PageId").val(),
cultureCode: $("#CultureSelector_CultureCode").val()
};
$.ajax({
url: "/odata/cms/Pages/Translate",
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
dataType: "json",
async: false
})
.done(function (json) {
//etc
我想看看是否有什么改变了关于安装在4版本的OData行动,但似乎(指同一:<一href=\"http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/odata-actions-and-functions\"相对=nofollow>动作和功能的OData V4使用的ASP.NET Web API 2.2 )
修改
我发现的OData V4
使用默认
命名空间并实现了,具体如下:
I found out that OData v4
uses a Default
namespace and implemented that, as follows:
首先,只是通过改变我的AJAX调用:
Firstly, just by changing my AJAX call to:
URL:/odata/cms/Pages/Default.Translate,
这没有工作,所以我也补充道:
That didn't work, so I also added:
[ODataRoute(Default.Translate)]
和
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
我的行动,按照这个链接的说明:的http://damienbod.word$p$pss.com/2014/06/16/web-api-and-odata-v4-crud-and-actions-part-3/..
to my action, as per the instructions at this link: http://damienbod.wordpress.com/2014/06/16/web-api-and-odata-v4-crud-and-actions-part-3/..
也没有工作。我已经按照步骤的信......无论我是盲目的,在这里失去了一些东西,或有与最新版本的一个严重的问题的OData code>为
的Web API
。
Also not working.. I have followed the steps to the letter... either I'm being blind and missing something here or there's a serious problem with the latest version of OData
for Web API
.
推荐答案
嗯,这是近一年这个问题,我真的试图移动到的OData V4 再次有同样的问题了。我忘了我原来的问题在这里,并要求一个新的,然后找到了答案。请参见的OData v4的函数总是返回更多细节404 。我很高兴地说,所有目前运作良好。
Well, it was almost a year after this question that I actually tried moving to OData v4 again and had the same problem. I forgot about my original question here and asked a new one and then found the answer. See OData v4 Function always returns 404 for more details. I'm glad to say all is working well now.
这篇关于网页API 2:4 OData的:操作返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!