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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:34:52+00:00 2026-05-13T05:34:52+00:00

I have a server side class which I make available on the client side

  • 0

I have a server side class which I make available on the client side through a [DataContract]. This class has a readonly field which I’d like to make available through a property. However, I’m unable to do so because it doesn’t seem that I’m allowed to add a [DataMember] property without having both get and set.

So – is there a way to have a [DataMember] property without setter?

[DataContract]
class SomeClass
{
    private readonly int _id; 

    public SomeClass() { .. }

    [DataMember]
    public int Id { get { return _id; } }        

    [DataMember]
    public string SomeString { get; set; }
}

Or will the solution be use the [DataMember] as the field – (like e.g. shown here)? Tried doing this too, but it doesn’t seem to care the field is readonly..?

Edit: Is the only way to make a readonly property by hacking it like this? (no – I don’t want to do this…)

[DataMember]
public int Id
{
    get { return _id; }
    private set { /* NOOP */ }
}
  • 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-13T05:34:53+00:00Added an answer on May 13, 2026 at 5:34 am

    Your “server-side” class won’t be “made available” to the client, really.

    What happens is this: based on the data contract, the client will create a new separate class from the XML schema of the service. It cannot use the server-side class per se!

    It will re-create a new class from the XML schema definition, but that schema doesn’t contain any of the .NET specific things like visibility or access modifiers – it’s just a XML schema, after all. The client-side class will be created in such a way that it has the same “footprint” on the wire – e.g. it serializes into the same XML format, basically.

    You cannot “transport” .NET specific know-how about the class through a standard SOAP-based service – after all, all you’re passing around are serialized messages – no classes!

    Check the “Four tenets of SOA” (defined by Don Box of Microsoft):

    1. Boundaries are explicit
    2. Services are autonomous
    3. Services share schema and contract, not class
    4. Compability is based upon policy

    See point #3 – services share schema and contract, not class – you only ever share the interface and XML schema for the data contract – that’s all – no .NET classes.

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

Sidebar

Ask A Question

Stats

  • Questions 308k
  • Answers 308k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer import java.io.Serializable; import javax.persistence.*; import org.hibernate.annotations.Type; import org.joda.time.DateTime; @Entity @Table(name… May 13, 2026 at 9:41 pm
  • Editorial Team
    Editorial Team added an answer Danny is onto something with the transparent window idea. But… May 13, 2026 at 9:41 pm
  • Editorial Team
    Editorial Team added an answer Since the definition is basically 'the doing of multiple things… May 13, 2026 at 9:41 pm

Related Questions

I am Developing a Registration Form in ASP.NET in Which I am using client
I have a set of largely static pages which I'd be happy to page
To make it simpler for a webapp to share files with another app on
I am writing a client/server app in C++ and need to realize simple protocol
I have no experience with threads, unfortunately. I have been doing a couple of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.