我在使用我的Odata服务处理MVC 4网站时遇到了一些麻烦。
你能帮我弄清楚我做错了吗?
这是我的WebApiConfig:
public static class WebApiConfig
{
/// <summary>
/// The Register method
/// </summary>
/// <param name="config">The config.</param>
public static void Register(HttpConfiguration config)
{
config.MapODataServiceRoute("odata", "odata", GetEdmModel(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
config.EnsureInitialized();
}
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.Namespace = "ThisClassesNamespace";
builder.ContainerName = "DefaultContainer";
builder.EntitySet<QueryRequest>("QueryRequests");
var edmModel = builder.GetEdmModel();
return edmModel;
}
}
这是global.asax的application_start方法:
protected void Application_Start()
{
Application["Name"] = "Administration Web Console";
GlobalConfiguration.Configure(WebApiConfig.Register);
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
Error += MvcApplication_Error;
var maplayerDao = new MapLayerDao();
maplayerDao.UpdateProvisioningData();
var factory = new CustomControllerFactory();
ControllerBuilder.Current.SetControllerFactory(factory);
}
最后,这是控制器获取方法的样子
public class QueryRequestsController : ODataController
{
private static ODataValidationSettings _validationSettings = new ODataValidationSettings();
private QueryRequestDao dao = new QueryRequestDao();
// GET: odata/QueryRequests
[HttpGet]
public IHttpActionResult GetQueryRequests()
{
// validate the query.
try
{
// queryOptions.Validate(_validationSettings);
}
catch (ODataException ex)
{
return BadRequest(ex.Message);
}
return Ok<IEnumerable<QueryRequest>>(dao.GetQueryRequests());
}
我可以在http://10.78.14.177:8040/odata/
处获取元数据给了我:
{
"@odata.context":"http://10.78.14.177:8040/odata/$metadata","value":[
{
"name":"QueryRequests","kind":"EntitySet","url":"QueryRequests"
}
] }
但是当我去http://10.78.14.177:8040/odata/QueryRequests时 我发现没有找到与请求URI匹配的HTTP资源&#39; http://10.78.14.177:8040/odata/QueryRequests&#39;。
我认为MVC路由正在获取此请求,而不是OData服务...但我不确定修复是什么。
有什么想法吗?