Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 389043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:49:43+00:00 2026-05-12T15:49:43+00:00

Should there be any problem passing this kind of a collection in WCF? class

  • 0

Should there be any problem passing this kind of a collection in WCF?

class Parent
{
  [DataMember]
  // some data members

  [DataMember]
  Child myChild;    
}

class Child : Parent
{
  [DataMember]     
  // some more data members

  [DataMember]
  Parent myParent;
}

Should there be any problem passing a list of Parent?

I get strange results, sometimes the channel faults, sometimes it doesn’t fault but gives me no data until I remove all the children from the list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:49:43+00:00Added an answer on May 12, 2026 at 3:49 pm

    First of all, you need to put the [DataContract] on every class that you want to have serialized and deserialized by WCF – it is not automatically inherited!

    [DataContract]
    class Parent
    {
       .....
    }
    
    [DataContract]
    class Child : Parent
    {
       .....
    }
    

    If you’re dealing with collections of things, then you might need to check into the CollectionDataContract :

    [CollectionDataContract]
    [KnownType(typeof(Parent))]
    [KnownType(typeof(Child))]
    public class CustomCollection : List<Parent>
    {
    }
    

    Also, WCF and SOA in general are quite a bit different from OOP and don’t handle inheritance all that well. You will most likely have to put [ServiceKnownTypes] or [KnownType] attributes on your service contracts in places where you want to use and support polymorphism.

    So if you have a service method that accepts a Parent, but should also be able to accept a Child instance as well, then you need to decorate the method with the [KnownType] attribute to make this information available to WCF.

    See the MSDN Documentation on the KnownType attribute, or check out this other SO question on the topic.

    Marc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should there be any specific order in which I should write the following for
Is there any reason why I should close the connection after a query or
Are there any big differences a developer should care about?
Is there any difference between the following two examples and should one be preferred
Is there any way to specify that a function should be called when a
Is there any penalty, such that you should only set them as nullable when
Is there any way to move an object forward in Three.js? Maybe I should
Is there any use for FormsAuthentication.Authenticate() is real-world web applications? Why should we write
Are there any counterindications to fork under mod_perl2? Should one use another way to
HD7970 vs FirePro V8800 Is there any reason why I should not go with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.