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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:35:23+00:00 2026-05-22T00:35:23+00:00

I have a new question for WCF gurus. So, I have a class User

  • 0

I have a new question for WCF gurus.

So, I have a class User which is close to the ‘User’ representation from the DB which I use for database operations. Now, I would like to have 2 different service contracts that use this class as data contract, but each in their own way… I mean,

public class DBLayer
{
    void InsertUsers(List<User> userList)
    {
        // both 'PropertyVisibleForService1' and 'PropertyVisibleForService2'
        // are used HERE to be inserted into their columns 
    }
}

[DataContract]
public class User
{
  [DataMember] public string PropertyVisibleOnlyForService1{...}
  [DataMember] public string PropertyVisibleOnlyForService2{...}
}

[ServiceContract]
public interface IService1  
{   
   List<User> GetUsers();  // user with 'PropertyVisibleOnlyForService1' inside
}

[ServiceContract]
public interface IService2  
{   
    List<User> GetUsers(); // user with 'PropertyVisibleOnlyForService2' inside 
}

So, the idea is that each service will get a different kind of user, subset of 'User'. Keeping in mind that I want to use the 'User' as is for DB operations, what would be my options to achieve this? Do I really need to create different data contracts or is there another smarter way?

Best would be to not only give me the solution, but also to explain me some best practices and alternatives.

Thank you in advance.

EDIT1:
I added a dummy DBLayer class here for a better overview and why I think the inheritance may not be good in this case.

A solution would be of having another ‘UserForService1‘ and ‘UserForService2‘ as data contracts which would map at the end from/into an ‘User‘ but I wanted some other points of view.

EDIT2: Very good article which helped me in this case: http://bloggingabout.net/blogs/vagif/archive/2009/03/29/iextensibledataobject-is-not-only-for-backward-compatibility.aspx

  • 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-22T00:35:23+00:00Added an answer on May 22, 2026 at 12:35 am

    You could create separate DTO’s for each service but your case would actually be ideal for a Decorator pattern:

    [DataContract]
    public class UserForService1 : User
    {
         private User mUser;
         public UserForService1(User u)
         {
             mUser = u;
         }
    
         //expose only properties you'd like the user of this data contract to see
         [DataMember]
         public string SomeProperty
         {
             get
             {
                //always call into the 'wrapped' object
                return mUser.SomeProperty;
             }
             set
             {
                mUser.SomeProperty = value;
             }
         }
         // etc...
    }
    

    and for Service2 similar code, that exposes only what you care for there…

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

Sidebar

Related Questions

From my last question , I have new idea for database protection. The following
I am new to WCF and have a simple question... My DataContract class returns
Following on from my previous question [link text][1] , I have a new problem.
I have inherited some Silverlight\WCF code and now need to implement some new features.
Question in title... In short - I have a WCF service exposing operations that
I'm pretty much new at WCF and have a performance question. I have the
I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I am new to C and i have this question. why does the following
I'm new to postgreSQL and I have a simple question: I'm trying to create
I'm new to Windows development and I have a question. I'm using a Mac

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.