WCF services

Starting with version 2.3, both the windows and Silverlight (Silverlight and WP7) libraries use the DataContractSerializer to (de)serialize xml by default for the ModelBase. The xml serialization technique supports complex nested object graphs. This means that classes deriving from ModelBase can be used to transfer data using WCF services.

 

With the help of the Catel.Fody plugin, it is possible to dynamically weave custom GetXmlSchema methods so no custom code is required to support WCF and DataContracts

 

There is no need to decorated the classes with DataMember or DataContract attributes with one single exception: when a class contains properties that are defined using a base class, the descending (or inherited) classes must be known. Catel could, in theory, reflect the whole AppDomain to gather these classes, but that would be a major hit on performance. Therefore the inherited classes must be defined manually using the KnownType attribute.

[Serializable, KnownType(Manager), KnownType(Employee)]
public class Job : ModelBase<Job>
{
    // abstract Person class which can be Manager or Employee
    public Person Person { get; set; }
} 

When adding the service reference, make sure to check the "Reuse types in all referenced assemblies" like shown in the image below: