Why can't I use the KnownType attribute in my WCF class?

I use WCF to retrieve a collection of objects. All objects are of type ProcedureText, but can have child classes SuspensionText or ResumptionText, both of which inherit from ProcedureText.

public class ProcedureText { }
public class SuspensionText : ProcedureText { }
public class ResumptionText : ProcedureText { }

My OperationContract specifies a method that returns an array of ProcessText objects:

[OperationContract]
[WebGet(UriTemplate = "procedureTexts")]
ProcedureText[] GetProcedureTexts();

This works if I pass all my objects to a ProcessText, but want to keep the difference in the use of subtypes. I was hoping to use the KnownType attribute for this and expected that I could do this by adding it to the ProcedureText class:

[System.Runtime.Serialization.KnownType(typeof(SuspensionTextDto))]
[System.Runtime.Serialization.KnownType(typeof(ResumptionTextDto))]
public class ProcedureText { }

, System.Runtime.Serialization.KnownType. , .NET Framework 4, .NET Framework 4, Target Frameweork .

?

+3

All Articles