【问题标题】:No HTTP resource was found that matches the request URI (...) for all tables未找到与所有表的请求 URI (...) 匹配的 HTTP 资源
【发布时间】:2015-02-19 21:08:35
【问题描述】:

this tutorial 为指导 (OData/EntityFramework/Asp.Net)。

我能够在根目录上执行一个简单的 GET 命令。

{
"@odata.context": "http://localhost:49624/$metadata",
"value": [
    {
        "name": "Appointments",
        "kind": "EntitySet",
        "url": "Appointments"
    },

    ......

    {
        "name": "Clients",
        "kind": "EntitySet",
        "url": "Clients"
    }
]
}

但任何比这更复杂的东西都会给我一个错误消息。 (我使用的是空 routePrefix。)

http://localhost:49624/Services

给我:

{
    "Message": "No HTTP resource was found that matches the request URI 'http://localhost:49624/Services'.",
    "MessageDetail": "No type was found that matches the controller named 'Services'."
}

这是我的超级简单的 GET

[EnableQuery]
public IQueryable<Service> Get()
{
    return db.Services;
}

如果重要的话,我会使用Postman 来测试这些命令。虽然我认为这不是一个因素。

我为每个表都有一个数据库和一个 DbSet。我不知道为什么我无法访问这些。

WebApiConfig:

        config.MapHttpAttributeRoutes();

        ODataModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<Appointment>("Appointments");
        builder.EntitySet<Service>("Services");
        builder.EntitySet<Employee>("Employees");
        builder.EntitySet<Client>("Clients");

        config.MapODataServiceRoute(
            routeName: "ODataRoute",
            routePrefix: null,
            model: builder.GetEdmModel());

如果这是一个基本问题,我很抱歉,但我对这一切真的很陌生,而且已经在这堵墙太久了哈哈。

【问题讨论】:

  • 您的控制器的名称是什么?您必须将其命名为 ServicesController
  • 天哪...谢谢你修复它。 (以前是“ServiceController”)

标签: asp.net http odata entity-framework-6


【解决方案1】:

上面的Jan Hommes在上面指出,控制器类需要复数(在我的例子中是ServiceController -> ServicesController)

【讨论】:

    猜你喜欢
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 2016-12-01
    • 2016-01-26
    相关资源
    最近更新 更多