How to configure known types dynamically

12 03 2011

Using WCF you may need to configure known types dynamically. Doing it is quite simple, you have to add your types (The types that you want to register dynamically) into the KnownTypes collection of the OperationDescription instance of your WCF service.

foreach (var operation in client.Endpoint.Contract.Operations)
{
  //_typeCollection is your known types collection that you want to register.
  foreach (Type type in _typeCollection)
  {
    operation.KnownTypes.Add(type);
    operation.KnownTypes.Add(type.MakeArrayType());
  }
}
Advertisements