ASMX Web service not serializing abstract base class

前端 未结 2 916
攒了一身酷
攒了一身酷 2021-01-17 17:48

I have an abstract class. Let\'s call it Lifeform. It looks something like:

public abstract class Lifeform {
    public virtual int Legs { get; set; }
    pu         


        
相关标签:
2条回答
  • 2021-01-17 18:25

    Ran into the exact same problem with VB.NET. Using the XMLInclude attribute, while ugly, did the trick.

    0 讨论(0)
  • 2021-01-17 18:30

    From what I've read, you can include the XMLInclude attribute on the web method returning the object rather than in the base class. Still not pretty, but might appeal to you a little more than putting derived class names in the base class. I haven't tried it out, but I think you can do something like this.

    [WebMethod]
    [XmlInclude(typeof(LifeForm))]
    public Human GetHuman()
    {
       return new Human();
    }
    
    0 讨论(0)
提交回复
热议问题