473,770 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why read/write properties for XmlSerializatio n

Hello,

I have a question about XmlSerializatio n. I have a class with a private
field called createDate of the type DateTime. In the constructor of my class
I use DateTime. Now to create a timestamp that is assigned to the field
createDate. Because I want to encapsulate as much as possible of my class
data and don't want clients of my class to change the createDate but only
read it, I encapsulate the createDate field with a get Property. Now I want
this class to be the return type of a WebService I created and I want
consumers of my WebService to be able to read the createDate from the Xml
response from the WebService, so I added the XmlElementAttri bute attribute to
my CreateDate property. The problem I run into is described on MSDN for the
XmlElementAttri bute:

"Apply the XmlElementAttri bute to public fields or public read/write
properties to control characteristics of the XML elements such as the element
name and namespace."

So, either the field needs to be public or my property needs to be a
read/write property. I think public fields are a bad practice in general, and
by adding a set method to my CreateDate property, I am opening up my class
more than I want to: clients of my class are now able to set the CreateDate
which I do not want them to be able to.

I hope you understand my problem here. Why should the XmlElementAttri bute be
applied to read/write properties only and not to read properties? And what is
the best practice for this situation? I do want the createDate to be in the
Xml result of my WebService, but I don't want clients of my class to be able
to set the createDate.
Mar 8 '06 #1
0 1006

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4777
by: Amith | last post by:
Hi, I am using an ActiveX created using delphi. It has a font property exposed. The font property is of type IFontDisp in the server(delphi). The font properties like Size, Bold, Underline etc has both 'Set' and 'Get' methods when using the activex in a VS6 app. But when using the activeX in a VS.NET app, the font properties are read only. The only way that i can set the font properties is by:
2
2101
by: Cory Burkhardt | last post by:
I am not sure what the suggested practice is for returning reference types from read-only properties. Consider an example: Suppose I have a Point class that is a reference type. I use the Point class from within a Shape class. I want the user of the Shape class to be able to see the location of the Shape but not be able to change it. So I declare a read-only property: class Shape { private Point location; /* other Shape stuff */
12
2027
by: Jens Thiel | last post by:
Hi, is there a reason for C# to require attribute arguments (properties) to be read-write while VB and C++ are happy with only a setter? Simplified Example: public sealed class FooAttribute : Attribute { private string s;
4
14948
by: Markus Brenner | last post by:
Hi there! Hope anybody can help. I want to at least read (maybe write) the extended file properties of office documents like winword, excel, .... I've tried two ways till now, one by opening the responding application (this method was to slow for my needs). The other way was using the dsofile.dll from microsoft. With that, first, it seemed to work.
6
2668
by: BBM | last post by:
I have an object that has a fairly complex construction sequence, so I have written a dedicated "factory" class that invokes the constructor of my object class (which does nothing but instantiate the object and set default blank/null values), and then does all the Db access and number crunching to populate the new object. The factory returns the fully populated object to the caller. All the fields in the object are private, but have...
0
2057
by: A programmer desperatly needing help! | last post by:
I use the xmlserialization on asp.net pages and on previous machines it never gave a problem. But now i somethings get a: Timed out waiting for a program to execute. The command being executed was "c:\winnt\microsoft.net\framework\v1.1.4322\csc.exe" /noconfig @"C:\DOCUME~1\...\ve3y0f-a.cmdline" error. It happens at random but occurs mostly when calling the XMLserialization multiple time rapidly. While looking at the .out file the error...
4
4016
by: pfrisbie | last post by:
I am developing a Web Services interface with C# and our partner is using Java (Axis 1.1). They require me to include xsi:types in the SOAP Messages I send them. For example: <Partner xmlns="urn:partner.xxxxx.com"> <RequestID>239</RequestID> <TimeStamp>2006-03-06T17:10:51.4662331-06:00</TimeStamp> <Subject xmlns:ns1="urn:partnermapping.xxxxxx.com" xsi:type="ns1:PartnerMapping"> <AccountID>98401</AccountID>
3
6990
by: LW | last post by:
Hi! I am getting the following error message for my fairly simple web service. I have classes and have two DataSets that reference the same classes. The error is: The XML element named 'GetCustNoResponse' from namespace 'http://mydomain/' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.
1
3967
by: Frank | last post by:
Hi, Let's say I have a file named myFile.xml Within that file I have blocks of data which I'd like to add at different times during the day. e.g. <LogEntry>
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.