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
In my case the solution is more simple.
I have a class that I return in all my mehotds, like this:
[DataContract]
public class Result
{
[DataMember]
public string KeyMensaje;
[DataMember]
public string ErrorMessage;
[DataMember]
public object Objeto;
...
}
The problem is due to Objeto object inside this class. This object is used to return variables types and it can't be serialized if is a complex object, for example:
res = new Result(list, "ok", "", "", "", null);
return res;
In this case object (list) is a list of other custom object, for example List
The solution is add on top Result class the complex types that object can be, like this:
[DataContract]
[KnownType(typeof(List))]
[KnownType(typeof(CustomEmployee))]
public class Result
{
...
}