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

Related Questions

I have a component which writes/generates javascript from a server side renderer. This component
I have done a bit of testing on this myself (During the server side
I have some dynamically created inputs which are not server-side controls. I want to
I have an html table which i bind data dynamically on the server side
I have a server side ImageButton, and a server side Button, and then a
I'm trying to adress the following issue: I have a server side .net application
I have to maintain a server-side script written in JScript (NOT Javascript) that needs
I currently have a fairly robust server-side validation system in place, but I'm looking
I have a master page that contains an ASP.NET server side Menu control (System.Web.UI.WebControls.Menu)
I have a basic HTML form that gets inserted into a server side div

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.