How to return a List<object> in WCF

后端 未结 3 1190
暖寄归人
暖寄归人 2020-12-20 10:00

I have my WCF service returning data both in XML and JSON format.

One functios has to return a List, because I don\'t know which class will be used to fill this list

3条回答
  •  萌比男神i
    2020-12-20 10:50

    You could define

    [KnownType(typeof(MyChildObject0))]
    ...
    [KnownType(typeof(MyChildObjectM))]
    public class MyBaseObject { ... }
    
    public class MyChildObject0 : MyBaseObject { ... }
    ...
    public class MyChildObjectM : MyBaseObject { ... }
    

    Or you could add the attribute only once and define static method that returns all M+1 types at once.

    and modify:

    public class WrapHome
    {
      ...
      public List CHART { get;set; }
    }
    

提交回复
热议问题