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

  • SEARCH
  • Home
  • 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 1083777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:28:43+00:00 2026-05-16T22:28:43+00:00

I want to inherit from a class which is located in a WCF Service.

  • 0

I want to inherit from a class which is located in a WCF Service. The Inheritance works fine (I see the properties of the base class in my child class), my problem occurs when I try to call a method from the service and pass the childtype as a parameter and not the basetype.

Base class in WCF Service (Pet):

[ServiceContract]
public interface IService
{
    [OperationContract]
    void BringPet(Pet pet);

    [OperationContract]
    void TakePet(Pet pet);

    [OperationContract]
    List<Pet> GetAllPets();
}

[DataContract]
public class Pet
{
    private string _name;
    private string _color;

    [DataMember]
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }

    [DataMember]
    public string Color
    {
        get { return _color; }
        set { _color = value; }
    }
}

Class on the client (Dog inherits from Pet):

[DataContract()]
class Dog : PetService.Pet
{
    [DataMember()]
    public bool HasPedigree { get; set; }
    [DataMember()]
    public string Race { get; set; }
}

When I try calling something like this:

        Dog dog = new Dog()
        {
            Color = "Black",
            Name = "Pluto",
            HasPedigree = true,
            Race = "Travolta"
        };

        _client.BringPet(dog);

I get a CommunicationException which says that the type Dog is not expected by the method BringPet(Pet pet).
I would solve this problem by setting the KnownType attributes on the service side, but because my service must not know the type Dog I can’t set the KnownType or ServiceKnownType attributes.

Can someone help me out?

  • 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-16T22:28:44+00:00Added an answer on May 16, 2026 at 10:28 pm

    I think this is very similar to this question: Service – client interface, architecture advice

    As you will see, there is no really easy way to do this without making your service operation more generic.

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

Sidebar

Related Questions

I need to inherit from a base class, one method of which has a
I want to make a class in C++, which other classes inherit from it.
I have two Parser classes that inherit from a base class, BaseParser. I want
I want to create a Class, say MyDiv , which inherits from the original
I have a model called Person. I want User to inherit from Person. class
Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
I have a class which inherit from DropCreateDatabaseIfModelChanges. public class SetupData : DropCreateDatabaseIfModelChanges<CyclingClubContext> {
I have a base type that I want to inherit from, for all my
I have a utility class from which I want to use one of the
I want to inherit a class named CSprite from another class named CDocument before

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.