ASMX Web service not serializing abstract base class

前端 未结 2 918
攒了一身酷
攒了一身酷 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: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();
    }
    

提交回复
热议问题