简体   繁体   中英

WCF derived DataContract does not inherit base DataContract's property

Below is my WCF DataContract base class

  [DataContract]
    public class BaseClass
    {
       //some datamembers
    }

And here is my derived class....

 [DataContract]
    public class DerivedClass1 : BaseClass
    {
       [DataMember]
       public string ProductName{get;set;}
    }

Due to some change in requirements, I am adding one more derived type which is also having same property 'ProductName'.

So code structure now is....

 [DataContract]
        public class BaseClass
        {
           //some datamembers
           [DataMember]
           public string ProductName{get;set;}
        }

[DataContract]
        public class DerivedClass1 : BaseClass
        {
           //[DataMember]
           //public string ProductName{get;set;}  property moved to base class
        }

[DataContract]
            public class DerivedClass2 : BaseClass
            {
               //some datamembers specific to DerivedClass2
            }

so I moved property 'ProductName' to base class. But now when existing datacontract is been called from client which returns me list of Derivedclass1, I don't see productName in response. Somehow, my DerivedClass1 is not ineriting productName property from base. What could be the reason? Am I making any mistake while writing code?

尝试对派生类使用[KnownType(typeof(BaseClass))]属性,并确保更新了服务引用。

I have tried this and it is working fine!

基本类型

Here is the SubClass SychRequests

儿童班

And this is what I got in Intellisense.

工作中

What else you are missing, can't say anything. If you can't see ProductName in response then that might be due to you are not sending it in your request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM