2014-12-01 1 views
0

RavenDb에서 "XmlElement"개체를 deserialize 할 수 없습니다. "XmlNodeConverter는 XmlDocuments 비 직렬화 만 지원합니다"라는 오류가 발생합니다.RavenDB : XmlNodeConverter는 XmlDocuments의 비 직렬화만을 지원합니다.

FooEventType 클래스의 코드는 (wsdl 및 xsd 파일의) Svcutil 도구에 의해 생성되었습니다. 이 클래스로

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:eglobal:eis:xsd:1")] 
public partial class FooEventType 
{ 
    private Foo[] fooListField; 

    private System.Xml.XmlElement[] anyField; 

    [System.Xml.Serialization.XmlArrayAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)] 
    [System.Xml.Serialization.XmlArrayItemAttribute("foo", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)] 
    public Foo[] fooList 
    { 
     get 
     { 
      return this.fooListField; 
     } 
     set 
     { 
      this.fooListField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAnyElementAttribute(Order = 1)] 
    public System.Xml.XmlElement[] Any 
    { 
     get 
     { 
      return this.anyField; 
     } 
     set 
     { 
      this.anyField = value; 
     } 
    } 

} 

는 RavenDb와 JSON의 직렬화 복원시 문제가 발생 유형 "XMLELEMENT"의 "모든"속성이 있습니다. 직렬화 중에는 아무런 문제가 없습니다. 내 데이터베이스에 연재

json으로 개체 :

{ 
    "fooList": [ 
    { 
     "Value": "test1" 
    }, 
    { 
     "Value": "test2" 
    } 
    ], 
    "Any": [ 
    { 
     "testOfProp": { 
     "#whitespace": [ 
      "\n", 
      "\n" 
     ], 
     "testOfValue": "XYZ" 
     } 
    } 
    ] 
} 

예외 세부 데이터베이스 내 쿼리 동안 직렬화 복원 :

System.InvalidOperationException was unhandled by user code 
    HResult=-2146233079 
    Message=Could not convert document FooEventTypes/8961 to entity of type EWcfService.FooEventType 
    Source=Raven.Client.Lightweight 
    StackTrace: 
     at Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertToEntity(Type entityType, String id, RavenJObject documentFound, RavenJObject metadata) 
     at Raven.Client.Document.InMemoryDocumentSessionOperations.TrackEntity(Type entityType, String key, RavenJObject document, RavenJObject metadata, Boolean noTracking) 
     at Raven.Client.Document.InMemoryDocumentSessionOperations.TrackEntity[T](String key, RavenJObject document, RavenJObject metadata, Boolean noTracking) 
     at Raven.Client.Document.SessionOperations.QueryOperation.Deserialize[T](RavenJObject result) 
     at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() 
     at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
     at Raven.Client.Document.SessionOperations.QueryOperation.Complete[T]() 
     at Raven.Client.Document.AbstractDocumentQuery`2.GetEnumerator() 
     at Raven.Client.Linq.RavenQueryInspector`1.GetEnumerator() 
     at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
     at Epcis11WcfService.RavenDb.RavenDbEpcis.poll(pollRequest request) in d:\Activite\PROJ\DEV\Main\ESolution2\ESolution2\E11WcfService\RavenDb\RavenDbE.cs:line 99 
     at E11WcfService.Query.poll(pollRequest request) in d:\Activite\PROJ\DEV\Main\ESolution2\ESolution2\E11WcfService\Query.svc.cs:line 47 
     at SyncInvokepoll(Object , Object[] , Object[]) 
     at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) 
     at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) 
    InnerException: Raven.Imports.Newtonsoft.Json.JsonSerializationException 
     HResult=-2146233088 
     Message=Could not read value for property: Any 
     Source=Raven.Abstractions 
     StackTrace: 
      at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) 
      at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) 
      at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) 
      at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) 
      at Raven.Imports.Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) 
      at Raven.Imports.Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) 
      at Raven.Client.Connection.DocumentConventionJsonExtensions.Deserialize(RavenJObject self, Type type, DocumentConvention convention) 
      at Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertToEntity(Type entityType, String id, RavenJObject documentFound, RavenJObject metadata) 
     InnerException: Raven.Imports.Newtonsoft.Json.JsonSerializationException 
      HResult=-2146233088 
      Message=XmlNodeConverter only supports deserializing XmlDocuments 
      Source=Raven.Abstractions 
      StackTrace: 
       at Raven.Imports.Newtonsoft.Json.Converters.XmlNodeConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) 
       at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue) 
       at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection wrappedList, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id) 
       at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id) 
       at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) 
       at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) 
       at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) 
      InnerException: 

답변

0

나는이 솔루션을 발견했다. getter/setter 덕분에 serialize 할 때 XmlElement []를 XmlDocument []로 변환하고 [XmlIgnore] 및 [JsonIgnore] 특성을 사용합니다. 하지만 다른 해결책이 있다면 나는 아직도 관심이 있습니다.

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:eglobal:eis:xsd:1")] 
public partial class FooEventType 
{ 
    private Foo[] fooListField; 

    private System.Xml.XmlDocument[] anyField; 

    [System.Xml.Serialization.XmlArrayAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)] 
    [System.Xml.Serialization.XmlArrayItemAttribute("foo", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)] 
    public Foo[] fooList 
    { 
     get 
     { 
      return this.fooListField; 
     } 
     set 
     { 
      this.fooListField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAnyElementAttribute(Order = 1)] 
    [JsonIgnore] 
    public XmlElement[] Any 
    { 
     get 
     { 
      return this.anyField.Select(x => x.DocumentElement).ToArray(); 
     } 
     set 
     { 
      if (value != null) 
      { 
       this.anyField = new XmlDocument[value.Count()]; 
       for (int i = 0; i < value.Count(); i++) 
       { 
        this.anyField[i] = new XmlDocument(); 
        this.anyField[i].LoadXml(value[i].OuterXml); 
       } 
      } 


     } 
    } 

    [System.Xml.Serialization.XmlIgnore] 
    [JsonProperty(PropertyName = "Any")] 
    public System.Xml.XmlDocument[] Any_ForRavenJsonSerialization 
    { 
     get 
     { 
      return this.anyField; 
     } 

     set 
     { 
      this.anyField = value; 
     } 
    } 

}