How to return a List<object> in WCF

后端 未结 3 1187
暖寄归人
暖寄归人 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条回答
  •  执笔经年
    2020-12-20 10:53

    To make it work, your service has to know the types it needs to serialize. If they cannot be found out by looking at your method's signature (for example because one type is object), you need to list all types that could possibly be in that object.

    Annotate them to the top of your service class, if you list for example can have instances of foo, bar and baz:

    [ServiceKnownType(typeof(foo))]
    [ServiceKnownType(typeof(bar))]
    [ServiceKnownType(typeof(baz))]
    

提交回复
热议问题