如何在WCF数据服务中修改请求正文

时间:2015-11-11 13:01:25

标签: c# wcf-data-services

我有一个WCF数据服务,当客户端发送新对象进行保存时,我收到反序列化错误,因为正文包含无效数据

An error occurred while processing this request.
   at: System.Data.Services.Serializers.ODataMessageReaderDeserializer.Deserialize(SegmentInfo segmentInfo)
   at: System.Data.Services.Serializers.Deserializer.ReadEntity(ResourceType& entityTypeInPayload)
   at: System.Data.Services.Serializers.Deserializer.HandlePostRequest(ResourceType& targetResourceType)
   at: System.Data.Services.DataService`1.HandlePostOperation(RequestDescription description, IDataService dataService)
   at: System.Data.Services.DataService`1.ProcessIncomingRequest(RequestDescription description, IDataService dataService)
   at: System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)
   at: System.Data.Services.DataService`1.HandleRequest()

Inner Exception: Cannot convert a primitive value to the expected type 'Edm.Int32'. See the inner exception for more details.
   at: Microsoft.Data.OData.AtomValueUtils.ConvertStringToPrimitive(String text, IEdmPrimitiveTypeReference targetTypeReference)
   at: Microsoft.Data.OData.AtomValueUtils.ReadPrimitiveValue(XmlReader reader, IEdmPrimitiveTypeReference primitiveTypeReference)
   at: Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueDeserializer.ReadNonEntityValueImplementation(IEdmTypeReference expectedTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean epmPresent, String propertyName)
   at: Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueDeserializer.ReadProperty(String expectedPropertyName, IEdmTypeReference expectedPropertyTypeReference, ODataNullValueBehaviorKind nullValueReadBehaviorKind, Boolean epmPresent)
   at: Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueDeserializer.ReadPropertiesImplementation(IEdmStructuredType structuredType, ReadOnlyEnumerable`1 properties, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Boolean epmPresent)
   at: Microsoft.Data.OData.Atom.ODataAtomEntryAndFeedDeserializer.ReadAtomContentElement(IODataAtomReaderEntryState entryState)
   at: Microsoft.Data.OData.Atom.ODataAtomEntryAndFeedDeserializer.ReadAtomElementInEntry(IODataAtomReaderEntryState entryState)
   at: Microsoft.Data.OData.Atom.ODataAtomEntryAndFeedDeserializer.ReadEntryContent(IODataAtomReaderEntryState entryState)
   at: Microsoft.Data.OData.Atom.ODataAtomReader.ReadAtEntryStartImplementation()
   at: Microsoft.Data.OData.ODataReaderCore.ReadImplementation()
   at: Microsoft.Data.OData.ODataReaderCore.ReadSynchronously()
   at: Microsoft.Data.OData.ODataReaderCore.InterceptException[T](Func`1 action)
   at: Microsoft.Data.OData.ODataReaderCore.Read()
   at: System.Data.Services.Serializers.EntityDeserializer.ReadEntry(ODataReader odataReader, SegmentInfo topLevelSegmentInfo)
   at: System.Data.Services.Serializers.EntityDeserializer.Read(SegmentInfo segmentInfo)
   at: System.Data.Services.Serializers.ODataMessageReaderDeserializer.Deserialize(SegmentInfo segmentInfo)

Inner Exception: Input string had an incorrect format.
   at: System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at: System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at: Microsoft.Data.OData.AtomValueUtils.ConvertStringToPrimitive(String text, IEdmPrimitiveTypeReference targetTypeReference)

   at: System.Data.Services.Serializers.ODataMessageReaderDeserializer.Deserialize(SegmentInfo segmentInfo)
   at: System.Data.Services.Serializers.Deserializer.ReadEntity(ResourceType& entityTypeInPayload)
   at: System.Data.Services.Serializers.Deserializer.HandlePostRequest(ResourceType& targetResourceType)
   at: System.Data.Services.DataService`1.HandlePostOperation(RequestDescription description, IDataService dataService)
   at: System.Data.Services.DataService`1.ProcessIncomingRequest(RequestDescription description, IDataService dataService)
   at: System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)
   at: System.Data.Services.DataService`1.HandleRequest()

我可以修改服务器端的请求正文以避免此错误吗?

0 个答案:

没有答案