Is there a generally accepted way to avoid having to use KnownType attributes on WCF services? I\'ve been doing some research, and it looks like there are two options:
The method mentioned by Bob will work as long as all involved classes are in the same assembly.
The following method will work across assemblies:
[DataContract]
[KnownType("GetDerivedTypes")]
public class BaseClass
{
public static List DerivedTypes = new List();
private static IEnumerable GetDerivedTypes()
{
return DerivedTypes;
}
}
[DataContract]
public class DerivedClass : BaseClass
{
//static constructor
static DerivedClass()
{
BaseClass.DerivedTypes.Add(typeof(DerivedClass));
}
}