Я использую следующие пакеты (выдержка):
<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 по каждому запросу.Я могу гарантировать, что моя база данных работает нормально.Я даже вижу это в отладчике.Мой контроллер и соответствующее действие вызывают (ODataParameters равен null
, что не должно), что также может коррелировать с этим.
Я установил .Net Version в 4.7 в облачной среде.Я также пробовал разные настройки в течение всего дня, но ничего не изменило.
Я думаю, что что-то не так со всем HttpConfiguration
материалом.
Кто-нибудь испытал это или у кого-то естьИдея, в чем может быть проблема?
Любая подсказка очень ценится.