473,782 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why do I need both, getter and setter accessor methods

This is my first attempt at writing/using web services, so any and all
comments will be greatly appreciated. With that said, I am also by no
means saying this is the correct either.

I have noticed that when returning a new TPastePart, created and
filled by the web service, that if the "PastePartI D" and "PastePart"
properties do not have "set" accessor methods, their respective data
is not returned, even though the object has contains that
information. So my solution, not one I like mind you, is to put in a
blank "set" method for each.

I have to main questions. First, why does this happen; and secondly,
what's the most appropriate way of doing this?
Thanks in advance,

Randel
//
*************** *************** *************** *************** **********
public class TPastePart{
//--------------------------------------------------------------------
private int FPastePartID;
private string FPastePart;
private string FPastePartNumbe r;
private string FPastePartDescr iption;

//--------------------------------------------------------------------
public TPastePart(){
FPastePartID = 0;

FPastePart = "";
FPastePartNumbe r = "";
FPastePartDescr iption = "";
}

//--------------------------------------------------------------------
public TPastePart(int PastePartID, string PastePartNumber ,
string PastePartDescri ption, string PastePart){

FPastePartID = PastePartID;

FPastePart = PastePart;
FPastePartNumbe r = PastePartNumber ;
FPastePartDescr iption = PastePartDescri ption;
}

//--------------------------------------------------------------------
public int PastePartID{
get{return(FPas tePartID);}
set{}
}

//--------------------------------------------------------------------
public string PastePart{
get{return(FPas tePart);}
set{}
}

//--------------------------------------------------------------------
public string PastePartNumber {
get{return(FPas tePartNumber);}

set{
FPastePartNumbe r = value;
FPastePart = FPastePartNumbe r + " " + FPastePartDescr iption;
}
}

//--------------------------------------------------------------------
public string PastePartDescri ption{
get{return(FPas tePartDescripti on);}

set{
FPastePartDescr iption = value;
FPastePart = FPastePartNumbe r + " " + FPastePartDescr iption;
}
}
}

//
*************** *************** *************** *************** **********
//***** WEB SERVICE
*************** *************** *************** *******
//
*************** *************** *************** *************** **********
//----------------------------------------------------------------------
[WebMethod(Descr iption="Retriev e the information for the given paste
part ID.")]
public TPastePart PastePart_Get(i nt PastePartID){
TPastePart PastePart = null;
ConnectionStrin gSettings Cs =
ConfigurationMa nager.Connectio nStrings["ECS"];

SqlConnection SqlCon = new SqlConnection() ;
SqlCommand SqlCmd = new SqlCommand();
SqlDataReader SqlReader = null;

try{
SqlCmd.CommandT ext = "ccisp_PastePar t_Get";
SqlCmd.CommandT ype = CommandType.Sto redProcedure;
SqlCmd.Connecti on = SqlCon;
SqlCmd.Paramete rs.Add(new SqlParameter("@ RETURN_VALUE",
SqlDbType.Int,
4,

ParameterDirect ion.ReturnValue ,
true,
((System.Byte)( 10)),
((System.Byte)( 0)),
"",
DataRowVersion. Current,
null));

SqlCmd.Paramete rs.Add(new SqlParameter("@ PastePartID",
SqlDbType.Int,
4,
ParameterDirect ion.Input,
false,
((System.Byte)( 10)),
((System.Byte)( 0)),
"",
DataRowVersion. Current,
PastePartID));

SqlCon.Connecti onString = (string)Cs.Conn ectionString;
SqlCon.Open();
SqlReader = SqlCmd.ExecuteR eader();

if(SqlReader.Ha sRows){
SqlReader.Read( );

PastePart = new TPastePart(SqlR eader.GetInt32( 0), //
PastePartID
SqlReader.GetSt ring(1), //
PastePartNumber
SqlReader.GetSt ring(2), //
PastePartDescri ption
SqlReader.GetSt ring(3)); //PastePart
}//END IF-STATEMENT "if(SqlReader.H asRows)"
}//END TRY-BLOCK
catch(Exception E){
HandleWebExcept ion(E);
}//END CATCH-BLOCK
finally{
SqlCon.Close();
}//END FINALLY-BLOCK

return(PastePar t);
}

//
*************** *************** *************** *************** **********
//***** WEB SERVICE RESULTS
*************** *************** **************
//
*************** *************** *************** *************** **********

//WITH "set" ACCESSOR
METHOD********* *************** *************** *****
<TPastePart>
<PastePartID> 1</PastePartID>
<PastePart>46-141 7% Platinum Paste</PastePart>
<PastePartNumbe r>46-141</PastePartNumber >
<PastePartDescr iption>7% Platinum Paste</PastePartDescri ption>
<PasteViscosity ID>1</PasteViscosityI D>
</TPastePart>
//
*************** *************** *************** *************** **********

//WITH OUT "set" ACCESSOR METHOD
*************** *************** *********
<TPastePart>
<PastePartNumbe r>46-141</PastePartNumber >
<PastePartDescr iption>7% Platinum Paste</PastePartDescri ption>
<PasteViscosity ID>1</PasteViscosityI D>
</TPastePart>
//
*************** *************** *************** *************** **********

Oct 17 '07 #1
2 1381
On Oct 17, 12:50 pm, rbjorkquist <rbjorkqu...@co ilcraft.comwrot e:
This is my first attempt at writing/using web services, so any and all
comments will be greatly appreciated. With that said, I am also by no
means saying this is the correct either.

I have noticed that when returning a new TPastePart, created and
filled by the web service, that if the "PastePartI D" and "PastePart"
properties do not have "set" accessor methods, their respective data
is not returned, even though the object has contains that
information. So my solution, not one I like mind you, is to put in a
blank "set" method for each.

I have to main questions. First, why does this happen; and secondly,
what's the most appropriate way of doing this?

Thanks in advance,

Randel

//
*************** *************** *************** *************** **********
public class TPastePart{
//--------------------------------------------------------------------
private int FPastePartID;
private string FPastePart;
private string FPastePartNumbe r;
private string FPastePartDescr iption;

//--------------------------------------------------------------------
public TPastePart(){
FPastePartID = 0;

FPastePart = "";
FPastePartNumbe r = "";
FPastePartDescr iption = "";
}

//--------------------------------------------------------------------
public TPastePart(int PastePartID, string PastePartNumber ,
string PastePartDescri ption, string PastePart){

FPastePartID = PastePartID;

FPastePart = PastePart;
FPastePartNumbe r = PastePartNumber ;
FPastePartDescr iption = PastePartDescri ption;
}

//--------------------------------------------------------------------
public int PastePartID{
get{return(FPas tePartID);}
set{}
}

//--------------------------------------------------------------------
public string PastePart{
get{return(FPas tePart);}
set{}
}

//--------------------------------------------------------------------
public string PastePartNumber {
get{return(FPas tePartNumber);}

set{
FPastePartNumbe r = value;
FPastePart = FPastePartNumbe r + " " + FPastePartDescr iption;
}
}

//--------------------------------------------------------------------
public string PastePartDescri ption{
get{return(FPas tePartDescripti on);}

set{
FPastePartDescr iption = value;
FPastePart = FPastePartNumbe r + " " + FPastePartDescr iption;
}
}

}

//
*************** *************** *************** *************** **********
//***** WEB SERVICE
*************** *************** *************** *******
//
*************** *************** *************** *************** **********
//----------------------------------------------------------------------
[WebMethod(Descr iption="Retriev e the information for the given paste
part ID.")]
public TPastePart PastePart_Get(i nt PastePartID){
TPastePart PastePart = null;
ConnectionStrin gSettings Cs =
ConfigurationMa nager.Connectio nStrings["ECS"];

SqlConnection SqlCon = new SqlConnection() ;
SqlCommand SqlCmd = new SqlCommand();
SqlDataReader SqlReader = null;

try{
SqlCmd.CommandT ext = "ccisp_PastePar t_Get";
SqlCmd.CommandT ype = CommandType.Sto redProcedure;
SqlCmd.Connecti on = SqlCon;
SqlCmd.Paramete rs.Add(new SqlParameter("@ RETURN_VALUE",
SqlDbType.Int,
4,

ParameterDirect ion.ReturnValue ,
true,
((System.Byte)( 10)),
((System.Byte)( 0)),
"",
DataRowVersion. Current,
null));

SqlCmd.Paramete rs.Add(new SqlParameter("@ PastePartID",
SqlDbType.Int,
4,
ParameterDirect ion.Input,
false,
((System.Byte)( 10)),
((System.Byte)( 0)),
"",
DataRowVersion. Current,
PastePartID));

SqlCon.Connecti onString = (string)Cs.Conn ectionString;
SqlCon.Open();
SqlReader = SqlCmd.ExecuteR eader();

if(SqlReader.Ha sRows){
SqlReader.Read( );

PastePart = new TPastePart(SqlR eader.GetInt32( 0), //
PastePartID
SqlReader.GetSt ring(1), //
PastePartNumber
SqlReader.GetSt ring(2), //
PastePartDescri ption
SqlReader.GetSt ring(3)); //PastePart
}//END IF-STATEMENT "if(SqlReader.H asRows)"
}//END TRY-BLOCK
catch(Exception E){
HandleWebExcept ion(E);
}//END CATCH-BLOCK
finally{
SqlCon.Close();
}//END FINALLY-BLOCK

return(PastePar t);

}

//
*************** *************** *************** *************** **********
//***** WEB SERVICE RESULTS
*************** *************** **************
//
*************** *************** *************** *************** **********

//WITH "set" ACCESSOR
METHOD********* *************** *************** *****
<TPastePart>
<PastePartID> 1</PastePartID>
<PastePart>46-141 7% Platinum Paste</PastePart>
<PastePartNumbe r>46-141</PastePartNumber >
<PastePartDescr iption>7% Platinum Paste</PastePartDescri ption>
<PasteViscosity ID>1</PasteViscosityI D>
</TPastePart>
//
*************** *************** *************** *************** **********

//WITH OUT "set" ACCESSOR METHOD
*************** *************** *********
<TPastePart>
<PastePartNumbe r>46-141</PastePartNumber >
<PastePartDescr iption>7% Platinum Paste</PastePartDescri ption>
<PasteViscosity ID>1</PasteViscosityI D>
</TPastePart>
//
*************** *************** *************** *************** **********
All,

Sorry for the double-post; it was unintentional.

Oct 17 '07 #2
Because the web service has to serialize your object to send it across the
wire. XML Serialization (not sure about binary) works by reading all the
public properties of your object and storing them in a simple XML format.
Then when the object reaches the other end, it needs to recreate the object
by passing these values back in to a newly created object by using the Set
method. Basically XML Serialization doesn't have access to private member
variables, it only knows about the public methods.

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"rbjorkquis t" <rb*********@co ilcraft.comwrot e in message
news:11******** **************@ v23g2000prn.goo glegroups.com.. .
This is my first attempt at writing/using web services, so any and all
comments will be greatly appreciated. With that said, I am also by no
means saying this is the correct either.

I have noticed that when returning a new TPastePart, created and
filled by the web service, that if the "PastePartI D" and "PastePart"
properties do not have "set" accessor methods, their respective data
is not returned, even though the object has contains that
information. So my solution, not one I like mind you, is to put in a
blank "set" method for each.

I have to main questions. First, why does this happen; and secondly,
what's the most appropriate way of doing this?
Thanks in advance,

Randel
//
*************** *************** *************** *************** **********
public class TPastePart{
//--------------------------------------------------------------------
private int FPastePartID;
private string FPastePart;
private string FPastePartNumbe r;
private string FPastePartDescr iption;

//--------------------------------------------------------------------
public TPastePart(){
FPastePartID = 0;

FPastePart = "";
FPastePartNumbe r = "";
FPastePartDescr iption = "";
}

//--------------------------------------------------------------------
public TPastePart(int PastePartID, string PastePartNumber ,
string PastePartDescri ption, string PastePart){

FPastePartID = PastePartID;

FPastePart = PastePart;
FPastePartNumbe r = PastePartNumber ;
FPastePartDescr iption = PastePartDescri ption;
}

//--------------------------------------------------------------------
public int PastePartID{
get{return(FPas tePartID);}
set{}
}

//--------------------------------------------------------------------
public string PastePart{
get{return(FPas tePart);}
set{}
}

//--------------------------------------------------------------------
public string PastePartNumber {
get{return(FPas tePartNumber);}

set{
FPastePartNumbe r = value;
FPastePart = FPastePartNumbe r + " " + FPastePartDescr iption;
}
}

//--------------------------------------------------------------------
public string PastePartDescri ption{
get{return(FPas tePartDescripti on);}

set{
FPastePartDescr iption = value;
FPastePart = FPastePartNumbe r + " " + FPastePartDescr iption;
}
}
}

//
*************** *************** *************** *************** **********
//***** WEB SERVICE
*************** *************** *************** *******
//
*************** *************** *************** *************** **********
//----------------------------------------------------------------------
[WebMethod(Descr iption="Retriev e the information for the given paste
part ID.")]
public TPastePart PastePart_Get(i nt PastePartID){
TPastePart PastePart = null;
ConnectionStrin gSettings Cs =
ConfigurationMa nager.Connectio nStrings["ECS"];

SqlConnection SqlCon = new SqlConnection() ;
SqlCommand SqlCmd = new SqlCommand();
SqlDataReader SqlReader = null;

try{
SqlCmd.CommandT ext = "ccisp_PastePar t_Get";
SqlCmd.CommandT ype = CommandType.Sto redProcedure;
SqlCmd.Connecti on = SqlCon;
SqlCmd.Paramete rs.Add(new SqlParameter("@ RETURN_VALUE",
SqlDbType.Int,
4,

ParameterDirect ion.ReturnValue ,
true,
((System.Byte)( 10)),
((System.Byte)( 0)),
"",
DataRowVersion. Current,
null));

SqlCmd.Paramete rs.Add(new SqlParameter("@ PastePartID",
SqlDbType.Int,
4,
ParameterDirect ion.Input,
false,
((System.Byte)( 10)),
((System.Byte)( 0)),
"",
DataRowVersion. Current,
PastePartID));

SqlCon.Connecti onString = (string)Cs.Conn ectionString;
SqlCon.Open();
SqlReader = SqlCmd.ExecuteR eader();

if(SqlReader.Ha sRows){
SqlReader.Read( );

PastePart = new TPastePart(SqlR eader.GetInt32( 0), //
PastePartID
SqlReader.GetSt ring(1), //
PastePartNumber
SqlReader.GetSt ring(2), //
PastePartDescri ption
SqlReader.GetSt ring(3)); //PastePart
}//END IF-STATEMENT "if(SqlReader.H asRows)"
}//END TRY-BLOCK
catch(Exception E){
HandleWebExcept ion(E);
}//END CATCH-BLOCK
finally{
SqlCon.Close();
}//END FINALLY-BLOCK

return(PastePar t);
}

//
*************** *************** *************** *************** **********
//***** WEB SERVICE RESULTS
*************** *************** **************
//
*************** *************** *************** *************** **********

//WITH "set" ACCESSOR
METHOD********* *************** *************** *****
<TPastePart>
<PastePartID> 1</PastePartID>
<PastePart>46-141 7% Platinum Paste</PastePart>
<PastePartNumbe r>46-141</PastePartNumber >
<PastePartDescr iption>7% Platinum Paste</PastePartDescri ption>
<PasteViscosity ID>1</PasteViscosityI D>
</TPastePart>
//
*************** *************** *************** *************** **********

//WITH OUT "set" ACCESSOR METHOD
*************** *************** *********
<TPastePart>
<PastePartNumbe r>46-141</PastePartNumber >
<PastePartDescr iption>7% Platinum Paste</PastePartDescri ption>
<PasteViscosity ID>1</PasteViscosityI D>
</TPastePart>
//
*************** *************** *************** *************** **********
Oct 30 '07 #3

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

Similar topics

2
3056
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers to have an easier time understanding what I do. Therefore this weekend I'm going to spend 3 days just writing comments. Before I do it, I thought I'd ask other programmers what information they find useful. Below is a typical class I've...
3
18090
by: Kiwi | last post by:
Hello. I know a getter can return other thing than a field. I know a setter can do more things than setting a field. I know there are "setter only" cases and "getter only" cases. I do use getters and setters when needed. But most of getter/setter pairs I have seen are just like below; > private int x; > public int getX() { return x; } > public void setX(int x) { this.x = x; }
4
5544
by: Jimbo | last post by:
I am sort of new to C#. Currently have a private property called "_name" in a class. I have written a public getter and setter routine for it called "Name". Currently, the getter for the property does some data manipulation before it returns the value. I wanted to add another getter to this property that would returnt the "Raw" value (what is stored in _name). Example:
1
1924
by: Steve | last post by:
I generate C# webservices proxy code from WSDL file, it turns out the classes generated have public member variables and no getter/setter methods as follows, and I am able to get data when running the client. public class MyFeeResponse {
12
3741
by: Adam Sandler | last post by:
Hi all, I hope this is an easy one... Using VWD 2005. When I call my accessor method (getName) I always receive an empty string back. Debugging shows there should be something there but I cannot figure out where the problem is actually occurring. The first couple of lines of my code behind: Partial Class _Default
3
99392
by: Martin Pöpping | last post by:
Hello, I´m coming from the Java World. Here Programmers often use (like in C++?) getter and setter methods. F.e.: class Mirror{ private int width_;
2
1409
by: Amie | last post by:
Hi, I have an atlas related question.. I have a web form that submits the information to a web service method, and it's done thru Atlas by binding the web methods to client functions. It seems to be working fine, except for when the class has a property with only getter (no setter), it freaks out, and returns the following
0
1194
by: shyamg | last post by:
Hi all i am newly add new Attribute "name" in strutshtml- tld file but its asking for setter method for attribute. where can add the setter and getter. Thanks. ss.
5
2516
by: javatech007 | last post by:
Hi, I've been at this question all day and still just don't know what to do. It's the last of all the questions I have to do and can't figure it out!! If anyone could help or give guidance it would be greatly appreciated!! Question: Write a class called shapes that accepts two variables into its constructor called a and b. Along with the getter and setter methods required, write a method called toPrinter() to output the coordinates of...
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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
10308
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
10076
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,...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
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
5375
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
4040
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
3633
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.