lundi 24 juillet 2017

Serialize a list of different object in c#

I'm coding a web service where I have these class

public class Result 
{
   public string Arc {get; set;} 
   public List<Parent> Parents {ger; set;}
}

public class abstract Parent 
{
}

public class ChildOne : Parent 
{ 
    public string Name {get; set;}
    public string Code {get; set;}
}
public class ChildTwo : Parent 
{ 
    public string Codebar {get; set;}
    public string Street {get; set;}
}

I have a function :

public Result MyFunction()
{
     Result result = new Result(); 

     ChildOne child1 = new ChildOne();
     result.Parents.Addchild1);     

     ChildTwo child2 = new ChildTwo();
     result.Parents.Add(child2);  

     return result;  
}

When I debug every thing is fine I see that my object ChildOne and ChildTwo was created and added to the list Parents. My problem is when I try to test My Web service using souapUi I get these errors

Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write6_Element(String n, String ns, Element o, Boolean isNullable, Boolean needType) Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write7_Rop(String n, String ns, Rop o, Boolean isNullable, Boolean needType) Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write13_Rop(Object o) Microsoft.Xml.Serialization.GeneratedAssembly.RopSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer) System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)

Can someone help me please ?




Aucun commentaire:

Enregistrer un commentaire