【发布时间】:2016-11-10 15:02:50
【问题描述】:
我正在重新实现 WCF 服务并选择使用 WebAPI 2.2 + OData v4。 我面临的问题是我需要包含“_”的路线,但我无法实现它。 目前我有这个:
public class AnnotationSharedWithController : ODataController
{
...
[EnableQuery]
public IQueryable<AnnotationSharedWith> Get()
{
return _unitOfWork.AnnotationSharedWith.Get();
}
...
}
我的 WebApiConfig.cs 看起来像这样:
public static void Register(HttpConfiguration config)
{
config.MapODataServiceRoute("webservice",null,GenerateEdmModel());
config.Count();
}
private static IEdmModel GenerateEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<AnnotationSharedWith>("annotation_shared_with");
return builder.GetEdmModel();
}
当我发出 GET 请求时,我收到以下错误
{ "Message": "没有找到与请求 URI 匹配的 HTTP 资源 'http://localhost:12854/annotation_shared_with'.", "MessageDetail": “没有找到与名为的控制器匹配的类型 'annotation_shared_with'。” }
【问题讨论】:
标签: c# asp.net-web-api2 odata