I have a base class with DataMember properties. I also have a derived class with DataMember properties. In my WCF project, I am returning a derived class. Is there a way to prevent a member in my base class from being serialized? Here is a sample code:
public class BaseClass { public string ShortDescription {get;set;} public string LongDescription {get;set;} } public class DerivedClass : BaseClass { public List<Description> Descriptions {get;set;} }
In this code, I want to be able to hide the inherited members of ShortDescription and LongDescription, because they are now deprecated. Any attempts to do this were unsuccessful. Here is what I tried:
public class DerivedClass : BaseClass { [DataMember] public List<Description> Descriptions {get;set;}
and
public class DerivedClass : BaseClass { [DataMember] public List<Description> Descriptions {get;set;}
None of these approaches worked. The DerivedClass type, when output to WSDL, still contains the "ignored" elements of the base class.
You may wonder why I am not just changing the base class. This is because I still use the base class in its original form as a previous version of the WSDL type to support backward compatibility for consumers. So I can have a call to v1000 that returns BaseClass and a call to V1010 that returns DerivedClass. I can add and change functionality to DerivedClass, all I want is without the ability to affect consumers of v1000 functionality.
wcf
omatase
source share