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.

Leave a Comment