无法使用ODataMediaTypeFormatter

时间:2016-09-06 13:27:01

标签: c# visual-studio asp.net-web-api odata dynamics-crm-2011

我正在运行一个WebApi 2.0服务器试图返回一个odataset,并在请求时:

http://localhost:5001/mydatasource/api/v2/AccountSet?$ filter = AccountNumber eq' 142530'& $ select = AccountNumber,AccountId

我收到以下异常:

  

{" odata.error":{       "代码":"",       " message":{         " lang":" en-US",         "值":"发生了错误。"       },       " innererror":{         " message":"' Microsoft.Crm.Sdk.Data.Services.OptionSetValue'无法使用ODataMediaTypeFormatter序列化。",         "输入":" System.Runtime.Serialization.SerializationException",         " stacktrace":"在System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateStructuralProperty(IEdmStructuralProperty)   structuralProperty,EntityInstanceContext entityInstanceContext)\ r \ n
  在   System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateStructuralPropertyBag(IEnumerable`1   structuralProperties,EntityInstanceContext entityInstanceContext)\ r \ n   在   System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateEntry(SelectExpandNode   selectExpandNode,EntityInstanceContext entityInstanceContext)\ r \ n
  在   System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteEntry(对象   graph,ODataWriter writer,ODataSerializerContext writeContext)\ r \ n
  在   System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteObjectInline(对象   graph,IEdmTypeReference expectedType,ODataWriter writer,   ODataSerializerContext writeContext)\ r \ n at   System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable的   enumerable,IEdmTypeReference feedType,ODataWriter writer,   ODataSerializerContext writeContext)\ r \ n at   System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline(对象   graph,IEdmTypeReference expectedType,ODataWriter writer,   ODataSerializerContext writeContext)\ r \ n at   System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(对象   图,类型类型,ODataMessageWriter messageWriter,   ODataSerializerContext writeContext)\ r \ n at   System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(类型   type,Object value,Stream writeStream,HttpContent内容,   HttpContentHeaders contentHeaders)\ r \ n at   System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(类型   type,Object value,Stream writeStream,HttpContent内容,   TransportContext transportContext,CancellationToken   cancellationToken)\ r \ n ---从前一个位置开始的堆栈跟踪结束   抛出异常的地方--- \ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.GetResult()\ r \ n at   System.Web.Http.Tracing.ITraceWriterExtensions.d__24.MoveNext(个)\ r \ n ---   从抛出异常的先前位置开始的堆栈跟踪结束   --- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)\ r \ n at   System.Runtime.CompilerServices.TaskAwaiter.GetResult()\ r \ n at   System.Web.Http.Owin.HttpMessageHandlerAdapter.d__13.MoveNext()"       }}

如果我只是要求2个不是选项集的字段,为什么要尝试序列化一个选项集?这适用于CRM 2011。

序列化odata选项集的正确方法是什么?

0 个答案:

没有答案