I am building these days another WCF service in order to perfom some actions, but the different between this WCF than others is that I have a base class that implements and describes common peroperties fro the derived classes, because I want to perfom actions generically.
Now, when I called the service method and sending the generic base class (that 'holds' the explicit class type of course) I bimped into a CommunicationException that claimed that the service failed to serialize thet the specific parameter that has been sent.
The solution for this failure is to add KnownType attribute above the base entity in order to specify types that should be recognized by the DataContractSerializer when serializing or deserializing a given type.
Some code snippet:
[DataContract]
[KnownType(typeof(User))]
public abstract class Entity
{
[DataMember(IsRequired = true)]
public int Id { get; set; }
[DataMember(IsRequired = true)]
public string Name { get; set; }
public Entity() { }
}
[DataContract]
public class User : Entity
{
[DataMember(IsRequired = true)]
public List<string> PossibleActions { get; set; }
}
This should solve the problem in the definition of KnownType in the base class. Now you can call your service method using non excplicit type (Entity) smoothly.