Asp.net web api Web Api OData控制器返回空白页无错误

Asp.net web api Web Api OData控制器返回空白页无错误,asp.net-web-api,odata,Asp.net Web Api,Odata,我正在使用Web Api和ODataController开发OData查询库。当我从web浏览器运行api时,它不会返回任何内容。我没有任何错误。我可以在VisualStudio中进行调试,并清楚地看到该方法运行并成功地将结果作为IQueryable返回。在引擎盖下的某个地方,它正在丢弃我的数据。还有其他人看到或遇到过这种情况吗?我已将我的代码包括在下面以供参考: using System; using System.Collections.Generic; using System.Linq;

我正在使用Web Api和ODataController开发OData查询库。当我从web浏览器运行api时,它不会返回任何内容。我没有任何错误。我可以在VisualStudio中进行调试,并清楚地看到该方法运行并成功地将结果作为IQueryable返回。在引擎盖下的某个地方,它正在丢弃我的数据。还有其他人看到或遇到过这种情况吗?我已将我的代码包括在下面以供参考:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.OData;
using Epm.Core.Model;
using System.Web.Http.OData.Query;
using Epm.Data.Access;
using Epm.Service.Assemblers;

namespace Epm.Service.Web.Controllers.OData
{
    public class SearchActionsController : ODataController
    {
        private readonly EpmEntities context = new EpmEntities();

        [Queryable(AllowedQueryOptions=AllowedQueryOptions.All)]
        public IQueryable<ActionStepDisplay> Get(int planId, int? factorId, bool? showArchived)
        {
            var user = this.GetCurrentUser();

            var results = (from p in context.SearchActions(user.SessionId, planId, factorId, showArchived, 1, null)
                           select p).ToModel().ToArray();

            return results.AsQueryable();
        }

        protected override void Dispose(bool disposing)
        {
            context.Dispose();
            base.Dispose(disposing);
        }
    }
}
我的配置:

ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Epm.Core.Model.ActionStep>("SearchActions");

Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();
config.Routes.MapODataRoute("ODataRoute", "odata", model);

问题可能在于MediaFormatter,它在控制器完成后被调用。当媒体类型格式化程序遇到对象a引用B和对象B引用a的引用循环时,您需要告诉媒体类型格式化程序如何处理该循环,因此在Json媒体类型格式化程序中,您可以执行以下操作

json.SerializerSettings.PreserveReferencesHandling = 
  Newtonsoft.Json.PreserveReferencesHandling.All;


我建议你用小提琴来看看到底发生了什么。您说您的浏览器没有收到响应,那么返回了什么HTTP代码?您可以使用Fiddler查找…

问题可能在于MediaFormatter,它在控制器完成后被调用。当媒体类型格式化程序遇到对象a引用B和对象B引用a的引用循环时,您需要告诉媒体类型格式化程序如何处理该循环,因此在Json媒体类型格式化程序中,您可以执行以下操作

json.SerializerSettings.PreserveReferencesHandling = 
  Newtonsoft.Json.PreserveReferencesHandling.All;

我建议你用小提琴来看看到底发生了什么。您说您的浏览器没有收到响应,那么返回了什么HTTP代码?您可以使用Fiddler找出…

您正在从方法返回ActionStepDisplay,但在builder中指定ActionStep作为实体

可能不可接受406在响应标题中,您从方法返回ActionStepDisplay,但在生成器中指定ActionStep作为实体


响应标题中的406可能不可接受

尝试在fiddler中运行查询,查看响应中是否有错误。尝试在fiddler中运行查询,查看响应中是否有错误。