在c#中序列化不同对象的列表

时间:2017-07-24 13:48:44

标签: c# web-services web soapui

我正在编写一个我有这些课程的网络服务

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;}
}

我有一个功能:

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

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

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

     return result;  
}

当我调试每件事情都很好时,我看到我的对象ChildOne和ChildTwo已经创建并添加到列表Parents。我的问题是,当我尝试使用souapUi测试我的Web服务时,我得到了这些错误

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)

有人能帮助我吗?

0 个答案:

没有答案