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 152257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:35:27+00:00 2026-05-11T09:35:27+00:00

I have an abstract class which I would like to be able to expose

  • 0

I have an abstract class which I would like to be able to expose to WCF so that any subclasses will also be able to be started as a WCF service.
This is what I have so far:

[ServiceContract(Name = 'PeopleManager', Namespace = 'http://localhost:8001/People')] [ServiceBehavior(IncludeExceptionDetailInFaults = true)] [DataContract(Namespace='http://localhost:8001/People')] [KnownType(typeof(Child))] public abstract class Parent {     [OperationContract]     [WebInvoke(Method = 'PUT', UriTemplate = '{name}/{description}')]     public abstract int CreatePerson(string name, string description);      [OperationContract]     [WebGet(UriTemplate = 'Person/{id}')]     public abstract Person GetPerson(int id); }  public class Child : Parent {     public int CreatePerson(string name, string description){...}     public Person GetPerson(int id){...} } 

When trying to create the service in my code I use this method:

public static void RunService() {     Type t = typeof(Parent); //or typeof(Child)     ServiceHost svcHost = new ServiceHost(t, new Uri('http://localhost:8001/People'));     svcHost.AddServiceEndpoint(t, new BasicHttpBinding(), 'Basic');     svcHost.Open(); } 

When using Parent as the type of service I get
The contract name 'Parent' could not be found in the list of contracts implemented by the service 'Parent'. OR Service implementation type is an interface or abstract class and no implementation object was provided.

and when using the Child as the type of service I get
The service class of type Namespace.Child both defines a ServiceContract and inherits a ServiceContract from type Namespace.Parent. Contract inheritance can only be used among interface types. If a class is marked with ServiceContractAttribute, then another service class cannot derive from it.

Is there a way to expose the functions in the Child class so I don’t have to specifically add the WCF attributes?

Edit
So this

[ServiceContract(Name= 'WCF_Mate', Namespace='http://localhost:8001/People')]       public interface IWcfClass{}        public abstract class Parent : IWcfClass {...}       public class Child : Parent, IWcfClass {...} 

with starting the service with Child returns
The contract type Namespace.Child is not attributed with ServiceContractAttribute. In order to define a valid contract, the specified type (either contract interface or service class) must be attributed with ServiceContractAttribute.

  • 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. 2026-05-11T09:35:28+00:00Added an answer on May 11, 2026 at 9:35 am

    The service contract is usually an interface, not a class. Place your contract into an interface, have the abstract class implement this interface, and let us know what happens when you use Child to start the service.

    Edit: Ok, now you need to modify your RunService method to this below. The contract type if IWcfClass, not Child or Parent.

    public static void RunService() {         Type t = typeof(Child);         ServiceHost svcHost = new ServiceHost(t, new Uri('http://localhost:8001/People'));         svcHost.AddServiceEndpoint(typeof(IWcfClass), new BasicHttpBinding(), 'Basic');         svcHost.Open(); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generic abstract base class from which I would like to derive
I have abstract BaseController, which basically looks like below: public abstract class BaseController :
I have an abstract base class that I use for services which includes the
I have an abstract class which contains method for setting header text. It looks
In my console application have an abstract Factory class Listener which contains code for
I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend
I have one parent class, which is abstract class for now, for four different
I have two classes (MVC view model) which inherits from one abstract base class.
I have an Abstract class called Function which has 2 inheriting classes (actually 6,
I have a series of 'tasks' that I would like to run in separate

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.