简体   繁体   English

找不到OData操作端点

[英]OData Action Endpoint not found

I am trying to link my api to braintree payment system. 我正在尝试将我的api链接到braintree付款系统。 I am using OData but I'm struggling with the routing of my endpoints. 我正在使用OData,但是我在端点的路由方面苦苦挣扎。 I keep getting a 404: 我不断收到404:

No HTTP resource was found that matches the request URI ' http://localhost:34403/odata/GetPlans '. 找不到与请求URI'http:// localhost:34403 / odata / GetPlans '匹配的HTTP资源。

Here is where i register my routes in the WebApiConfig class: 这是我在WebApiConfig类中注册路由的地方:

var GetPlans = builder.Action("GetPlans");

Should I be using something else besides Action? 除了动作外,我还应该使用其他东西吗? Maybe return something else? 也许还别的东西?

Here is the endpoint I am trying to hit: 这是我尝试达到的端点:

    [HttpGet]
    [ODataRoute("GetPlans")]
    public IHttpActionResult getPlans()
    {
        var gateway = new BraintreeGateway
        {
            Environment = Braintree.Environment.SANDBOX,
            MerchantId = merchId,
            PublicKey = pubKey,
            PrivateKey = privKey
        };

        List<Plan> plans = gateway.Plan.All();

        return Ok(plans);

    }

Actions require the POST http verb, but you have the HttpGet attribute on your method, change it to the POST one and ensure that you are using the POST verb when calling the method. 操作需要POST http动词,但是方法上具有HttpGet属性,将其更改为POST,并确保在调用方法时使用POST动词。 Alternatively, you could change this to be a function, which uses a GET, you would need to use the Function method on the builder instead, like this: 另外,您可以将其更改为使用GET的函数,而需要在构建器上使用Function方法,如下所示:

var GetPlans = builder.Function("GetPlans");

A quick summary of the difference between actions and functions from http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/odata-actions-and-functions http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/odata-actions-and-functions中的动作和功能之间的差异的简要概述

Functions are operations that do not have side effects, may support further composition and must have return type. 函数是没有副作用的操作,可能支持进一步的编写并且必须具有返回类型。

Actions are operations that allow side effects, such as data modification, and cannot be further composed in order to avoid non-deterministic behavior. 动作是允许副作用(例如数据修改)的操作,并且为了避免非确定性行为,无法进行进一步组合。

Actions require the POST action because they may have side effects. 操作需要POST操作,因为它们可能会有副作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM