WCF: Configuring Known Types

I guess I have found the answer now. The configuration file I posted above looks like this: <?xml version=”1.0″ encoding=”utf-8″ ?> <configuration> <system.runtime.serialization> <dataContractSerializer> <declaredTypes> <add type=”Person, WCFWithNoLibrary, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”> <knownType type=”Employee, WCFWithNoLibrary, Version=1.0.0.0,Culture=neutral, PublicKeyToken=null” /> </add> </declaredTypes> </dataContractSerializer> </system.runtime.serialization> <system.serviceModel> ……. </system.serviceModel> </configuration> What I just added was, the Namespace of the Person class and … Read more

How do you configure WCF known types programmatically?

Add [ServiceKnownType] to your [ServiceContract] interface: [ServiceKnownType(“GetKnownTypes”, typeof(KnownTypesProvider))] then create a class called KnownTypesProvider: internal static class KnownTypesProvider { public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider) { // collect and pass back the list of known types } } and then you can pass back whatever types you need.