简体   繁体   中英

Web Service and System.InvalidOperationException while serializing

I have the following class which throws an InvalidOperationException when the class is serialized

public class CustomFieldList : CustomField, IList
  {
        public CustomFieldList()
        {
              this.ControlType = Rflex.Framework.MetaData.ControlType.DDL;
        }
        public Type ReferentielType { get; set; }
        public int? CustomCodeTableTypeID { get; set; }
        public CustomCodeTableItem Value { get; set; }
        public override object TheValue { get { return Value; } }
  }

It can't serialize Type which maybe is a normal thing ?

The stack (error translated from French so it's not accurate) :

System.InvalidOperationException: Error while processing XML. ---> System.InvalidOperationException: The type Rflex.WebServices.Objects.Reference.CustomCodeTableItem is not recognized. use XmlInclude or SoapInclude attribute to specify types ..... à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write32_Type(String n, String ns, Type o, Boolean isNullable, Boolean needType) à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write33_CustomFieldList(String n, String ns, CustomFieldList o, Boolean isNullable, Boolean needType) à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write74_JobDescription(String n, String ns, JobDescription o, Boolean isNullable, Boolean needType) à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write77_Offer(String n, String ns, Offer o, Boolean isNullable, Boolean needType) à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write96_Offer(Object o) à Microsoft.Xml.Serialization.GeneratedAssembly.OfferSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer) à System.Xml.Serialization.XmlSerializer.Serialize( XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)

I tried with attributes but it doesn't want to work.

Thanks in advacnce.

You'll need this:

[XmlInclude(typeof(Rflex.WebServices.Objects.Reference.CustomCodeTableItem))]

added to the type that is actually returned from your web service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM