2017-05-02 6 views
1

제 웹 서비스에서 배치 요청을 설정했습니다. 나는 단지 DefaultODataBatchHandler 클래스를 줄 바꿈 점을 추가하기 위해 감쌌다. 요청을 성공적으로 처리하고 CreateResponseMessageAsync 메서드가 200 OK 응답을 생성합니다. 그러나 클라이언트가 다음을 받고 있습니다.OData v4 DefaultODataBatchHandler NotImplementedException

{ 
    "Message": "An error has occurred.", 
    "ExceptionMessage": "The method or operation is not implemented.", 
    "ExceptionType": "System.NotImplementedException", 
    "StackTrace": " at System.Web.HttpContextBase.get_Response()\r\n at System.Web.UI.Util.GetUrlWithApplicationPath(HttpContextBase context, String url)\r\n at System.Web.Routing.RouteCollection.NormalizeVirtualPath(RequestContext requestContext, String virtualPath)\r\n at System.Web.Routing.RouteCollection.GetVirtualPath(RequestContext requestContext, String name, RouteValueDictionary values)\r\n at System.Web.Http.WebHost.Routing.HostedHttpRouteCollection.GetVirtualPath(HttpRequestMessage request, String name, IDictionary`2 values)\r\n at System.Web.Http.Routing.UrlHelper.GetVirtualPath(HttpRequestMessage request, String routeName, IDictionary`2 routeValues)\r\n at System.Web.Http.Routing.UrlHelper.Route(String routeName, IDictionary`2 routeValues)\r\n at System.Web.Http.Routing.UrlHelper.Link(String routeName, IDictionary`2 routeValues)\r\n at System.Web.OData.Extensions.UrlHelperExtensions.CreateODataLink(UrlHelper urlHelper, String routeName, IODataPathHandler pathHandler, IList`1 segments)\r\n at System.Web.OData.Extensions.UrlHelperExtensions.CreateODataLink(UrlHelper urlHelper, IList`1 segments)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.GetDefaultBaseAddress(HttpRequestMessage request)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.GetBaseAddressInternal(HttpRequestMessage request)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Net.Http.HttpContent.<CopyToAsyncCore>d__44.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.OData.Batch.ODataBatchResponseItem.<WriteMessageAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.OData.Batch.ODataBatchContent.<SerializeToStreamAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Net.Http.HttpContent.<LoadIntoBufferAsyncCore>d__49.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Owin.HttpMessageHandlerAdapter.<BufferResponseContentAsync>d__13.MoveNext()" 
} 

나는 이것이 어디서 왔는지 알 수 없습니다.

ODataConfig.cs

public static void Register(HttpConfiguration config) 
    { 
     config.MapHttpAttributeRoutes(); 

     config.Routes.MapHttpRoute(
      name: "DefaultApi", 
      routeTemplate: "api/{controller}/{id}", 
      defaults: new { id = RouteParameter.Optional } 
     ); 

     var builder = new ODataConventionModelBuilder(); 

     var tags = builder.EntitySet<EventTag>("EventTags"); 
     tags.HasOptionalBinding(x => x.Parent, tags); 

     var events = builder.EntitySet<Event>("Events"); 
     events.HasManyBinding(x => x.Tags, tags); 

     var batchHandler = new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer); 

     config.MapODataServiceRoute("odata", "odata", builder.GetEdmModel(), batchHandler); 
    } 
} 

답변

0

나는 오히려 전에에서 하나를 (내가에 Autofac을 유선었던)을 다시 사용하는 것보다, HttpConfiguration의 새로운 인스턴스 등록으로 불리는 확인하여이 문제를 해결 . 너가 GlobalConfiguration.Configuration을 사용하여 이것을 위로 철사 잡는 것을 시도하면 너는 너가 동일한 문제를 얻을 수 있었다는 것을 짐작한다.

트릭은 새로운 HttpConfiguration 인스턴스에 WebApi를 설정하는 것입니다.