我正在使用以下软件包(摘录):
<package id="Microsoft.AspNet.OData" version="6.1.0" targetFramework="net461" />
<package id="Microsoft.AspNet.OData.Versioning" version="2.2.0" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi" version="5.2.4" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.4" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.4" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.OData" version="5.7.0" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.4" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.4" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.Versioning" version="2.3.0" targetFramework="net461" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.4" targetFramework="net461" />
<package id="Microsoft.OData.Core" version="7.4.4" targetFramework="net461" />
<package id="Microsoft.OData.Edm" version="7.4.4" targetFramework="net461" />
<package id="Microsoft.Owin" version="4.0.0" targetFramework="net461" />
<package id="Microsoft.Owin.Cors" version="4.0.0" targetFramework="net461" />
我使用以下配置代码(也是摘录):
IEnumerable<ODataMediaTypeFormatter> formatters = ODataMediaTypeFormatters.Create();
httpConfiguration.Formatters.InsertRange(0, formatters);
httpConfiguration.MapHttpAttributeRoutes();
httpConfiguration.MapODataServiceRoute("OData", "v1.0", modelBuilder.GetEdmModels().First());
app.UseWebApi(httpServer);
请注意,我禁用了版本化的API部分,因为我认为这可能是原因,但事实证明,它并非如此。错误仍然是一样的。通常,对于我的所有配置,我都使用
HttpServer httpServer = GlobalConfiguration.DefaultServer;
HttpConfiguration httpConfiguration = httpServer.Configuration;
我总是使用相同的httpConfiguration
变量。无论我调用哪个URL,它可能是一个集合上的简单GET或本地的OData操作(IIS)一切正常。我记得我在开始时对格式化程序有些麻烦但是当前版本在本地都很好。
将代码上传到Azure进入临时环境后,所有与OData相关的请求都将停止工作。这是一个痕迹:
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Type='HttpError', formatters=[MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, FormUrlEncodedMediaTypeFormatterTracer, FormUrlEncodedMediaTypeFormatterTracer]', Operation=PerRequestContentNegotiator.Negotiate
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use new 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'FormUrlEncodedMediaTypeFormatter' for type='HttpError', mediaType='application/json'', Operation=FormUrlEncodedMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use same 'FormUrlEncodedMediaTypeFormatter' formatter', Operation=FormUrlEncodedMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'JQueryMvcFormUrlEncodedFormatter' for type='HttpError', mediaType='application/json'', Operation=JQueryMvcFormUrlEncodedFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use same 'JQueryMvcFormUrlEncodedFormatter' formatter', Operation=JQueryMvcFormUrlEncodedFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Type='HttpError', formatters=[MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, MediaTypeFormatterTracer, FormUrlEncodedMediaTypeFormatterTracer, FormUrlEncodedMediaTypeFormatterTracer]', Operation=DefaultContentNegotiator.Negotiate
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Obtaining formatter of type 'ODataMediaTypeFormatter' for type='HttpError', mediaType='application/json; charset=utf-8'', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Will use same 'ODataMediaTypeFormatter' formatter', Operation=ODataMediaTypeFormatter.GetPerRequestFormatterInstance
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Selected formatter='ODataMediaTypeFormatter', content-type='application/json; charset=utf-8'', Operation=DefaultContentNegotiator.Negotiate
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Selected formatter='ODataMediaTypeFormatter', content-type='application/json; charset=utf-8'', Operation=PerRequestContentNegotiator.Negotiate
2018-04-24T13:39:30 PID[7936] Information [2018-04-24T13:39:30.3614885Z] Level=Info, Kind=Begin, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Message='Value='System.Web.Http.HttpError', type='HttpError', content-type='application/json; odata.metadata=minimal'', Operation=ODataMediaTypeFormatter.WriteToStreamAsync
2018-04-24T13:39:30 PID[7936] Error [2018-04-24T13:39:30.3614885Z] Level=Error, Kind=End, Category='System.Net.Http.Formatting', Id=800002ee-0000-ef00-b63f-84710c7967bb, Operation=ODataMediaTypeFormatter.WriteToStreamAsync, Exception=System.NotImplementedException: The method or operation is not implemented.
at System.Web.HttpContextBase.get_Response()
at System.Web.UI.Util.GetUrlWithApplicationPath(HttpContextBase context, String url)
at System.Web.Routing.RouteCollection.NormalizeVirtualPath(RequestContext requestContext, String virtualPath)
at System.Web.Routing.RouteCollection.GetVirtualPath(RequestContext requestContext, String name, RouteValueDictionary values)
at System.Web.Http.WebHost.Routing.HostedHttpRouteCollection.GetVirtualPath(HttpRequestMessage request, String name, IDictionary`2 values)
at System.Web.Http.Routing.UrlHelper.GetVirtualPath(HttpRequestMessage request, String routeName, IDictionary`2 routeValues)
at System.Web.Http.Routing.UrlHelper.Link(String routeName, IDictionary`2 routeValues)
at System.Web.OData.Formatter.ODataMediaTypeFormatter.GetDefaultBaseAddress(HttpRequestMessage request)
at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)
at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__19.MoveNext()
似乎它想要序列化HttpError
对象,但它不能。我不知道那个错误对象是什么,因为我看不到。我的代码不会创建这样的对象。我知道验证确实如此,但我还没有验证任何内容。
即使拨打$metadata
也会导致此错误。该服务在每个请求上返回500。我可以保证我的数据库连接正常工作。我甚至可以在调试器中看到这一点。我的控制器和相应的Action被调用(ODataParameters是null
它不应该),这也可能与此相关。
我确实在云环境中将.Net版本设置为4.7。我也整天尝试了不同的设置,但没有任何区别。
我的猜测是整个HttpConfiguration
的东西出了问题。
有没有人经历过这个或有没有人知道问题可能是什么?
非常感谢任何提示。
答案 0 :(得分:0)
降级到.net 4.6.1并可以将此节点添加到Web配置文件
<system.web>
<compilation targetFramework="4.6.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
答案 1 :(得分:0)
我设法解决了这个问题。这是微不足道的。我不知道为什么,但HttpContext
杀了它。我查看了堆栈跟踪,并在WebApi中的某个时刻看到它试图从HttpRequestMessage
null
获得style={{ transition: 'none' }}
。因此,最终的解决方案是完全删除此调用。
我发现这是因为我拼命地重新创建整个项目并逐行复制:(
感谢@NinjaDeveloper的回答。我尝试过但它没有改变任何东西。我也尝试了其他各种组合。