473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 "PastePartID" 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 FPastePartNumber;
private string FPastePartDescription;

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

FPastePart = "";
FPastePartNumber = "";
FPastePartDescription = "";
}

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

FPastePartID = PastePartID;

FPastePart = PastePart;
FPastePartNumber = PastePartNumber;
FPastePartDescription = PastePartDescription;
}

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

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

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

set{
FPastePartNumber = value;
FPastePart = FPastePartNumber + " " + FPastePartDescription;
}
}

//--------------------------------------------------------------------
public string PastePartDescription{
get{return(FPastePartDescription);}

set{
FPastePartDescription = value;
FPastePart = FPastePartNumber + " " + FPastePartDescription;
}
}
}

//
************************************************** ********************
//***** WEB SERVICE
************************************************** **
//
************************************************** ********************
//----------------------------------------------------------------------
[WebMethod(Description="Retrieve the information for the given paste
part ID.")]
public TPastePart PastePart_Get(int PastePartID){
TPastePart PastePart = null;
ConnectionStringSettings Cs =
ConfigurationManager.ConnectionStrings["ECS"];

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

try{
SqlCmd.CommandText = "ccisp_PastePart_Get";
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Connection = SqlCon;
SqlCmd.Parameters.Add(new SqlParameter("@RETURN_VALUE",
SqlDbType.Int,
4,

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

SqlCmd.Parameters.Add(new SqlParameter("@PastePartID",
SqlDbType.Int,
4,
ParameterDirection.Input,
false,
((System.Byte)(10)),
((System.Byte)(0)),
"",
DataRowVersion.Current,
PastePartID));

SqlCon.ConnectionString = (string)Cs.ConnectionString;
SqlCon.Open();
SqlReader = SqlCmd.ExecuteReader();

if(SqlReader.HasRows){
SqlReader.Read();

PastePart = new TPastePart(SqlReader.GetInt32(0), //
PastePartID
SqlReader.GetString(1), //
PastePartNumber
SqlReader.GetString(2), //
PastePartDescription
SqlReader.GetString(3)); //PastePart
}//END IF-STATEMENT "if(SqlReader.HasRows)"
}//END TRY-BLOCK
catch(Exception E){
HandleWebException(E);
}//END CATCH-BLOCK
finally{
SqlCon.Close();
}//END FINALLY-BLOCK

return(PastePart);
}

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

//WITH "set" ACCESSOR
METHOD********************************************
<TPastePart>
<PastePartID>1</PastePartID>
<PastePart>46-141 7% Platinum Paste</PastePart>
<PastePartNumber>46-141</PastePartNumber>
<PastePartDescription>7% Platinum Paste</PastePartDescription>
<PasteViscosityID>1</PasteViscosityID>
</TPastePart>
//
************************************************** ********************

//WITH OUT "set" ACCESSOR METHOD
***************************************
<TPastePart>
<PastePartNumber>46-141</PastePartNumber>
<PastePartDescription>7% Platinum Paste</PastePartDescription>
<PasteViscosityID>1</PasteViscosityID>
</TPastePart>
//
************************************************** ********************

Oct 17 '07 #1
2 1367
On Oct 17, 12:50 pm, rbjorkquist <rbjorkqu...@coilcraft.comwrote:
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 "PastePartID" 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 FPastePartNumber;
private string FPastePartDescription;

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

FPastePart = "";
FPastePartNumber = "";
FPastePartDescription = "";
}

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

FPastePartID = PastePartID;

FPastePart = PastePart;
FPastePartNumber = PastePartNumber;
FPastePartDescription = PastePartDescription;
}

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

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

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

set{
FPastePartNumber = value;
FPastePart = FPastePartNumber + " " + FPastePartDescription;
}
}

//--------------------------------------------------------------------
public string PastePartDescription{
get{return(FPastePartDescription);}

set{
FPastePartDescription = value;
FPastePart = FPastePartNumber + " " + FPastePartDescription;
}
}

}

//
************************************************** ********************
//***** WEB SERVICE
************************************************** **
//
************************************************** ********************
//----------------------------------------------------------------------
[WebMethod(Description="Retrieve the information for the given paste
part ID.")]
public TPastePart PastePart_Get(int PastePartID){
TPastePart PastePart = null;
ConnectionStringSettings Cs =
ConfigurationManager.ConnectionStrings["ECS"];

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

try{
SqlCmd.CommandText = "ccisp_PastePart_Get";
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Connection = SqlCon;
SqlCmd.Parameters.Add(new SqlParameter("@RETURN_VALUE",
SqlDbType.Int,
4,

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

SqlCmd.Parameters.Add(new SqlParameter("@PastePartID",
SqlDbType.Int,
4,
ParameterDirection.Input,
false,
((System.Byte)(10)),
((System.Byte)(0)),
"",
DataRowVersion.Current,
PastePartID));

SqlCon.ConnectionString = (string)Cs.ConnectionString;
SqlCon.Open();
SqlReader = SqlCmd.ExecuteReader();

if(SqlReader.HasRows){
SqlReader.Read();

PastePart = new TPastePart(SqlReader.GetInt32(0), //
PastePartID
SqlReader.GetString(1), //
PastePartNumber
SqlReader.GetString(2), //
PastePartDescription
SqlReader.GetString(3)); //PastePart
}//END IF-STATEMENT "if(SqlReader.HasRows)"
}//END TRY-BLOCK
catch(Exception E){
HandleWebException(E);
}//END CATCH-BLOCK
finally{
SqlCon.Close();
}//END FINALLY-BLOCK

return(PastePart);

}

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

//WITH "set" ACCESSOR
METHOD********************************************
<TPastePart>
<PastePartID>1</PastePartID>
<PastePart>46-141 7% Platinum Paste</PastePart>
<PastePartNumber>46-141</PastePartNumber>
<PastePartDescription>7% Platinum Paste</PastePartDescription>
<PasteViscosityID>1</PasteViscosityID>
</TPastePart>
//
************************************************** ********************

//WITH OUT "set" ACCESSOR METHOD
***************************************
<TPastePart>
<PastePartNumber>46-141</PastePartNumber>
<PastePartDescription>7% Platinum Paste</PastePartDescription>
<PasteViscosityID>1</PasteViscosityID>
</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
"rbjorkquist" <rb*********@coilcraft.comwrote in message
news:11**********************@v23g2000prn.googlegr oups.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 "PastePartID" 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 FPastePartNumber;
private string FPastePartDescription;

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

FPastePart = "";
FPastePartNumber = "";
FPastePartDescription = "";
}

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

FPastePartID = PastePartID;

FPastePart = PastePart;
FPastePartNumber = PastePartNumber;
FPastePartDescription = PastePartDescription;
}

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

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

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

set{
FPastePartNumber = value;
FPastePart = FPastePartNumber + " " + FPastePartDescription;
}
}

//--------------------------------------------------------------------
public string PastePartDescription{
get{return(FPastePartDescription);}

set{
FPastePartDescription = value;
FPastePart = FPastePartNumber + " " + FPastePartDescription;
}
}
}

//
************************************************** ********************
//***** WEB SERVICE
************************************************** **
//
************************************************** ********************
//----------------------------------------------------------------------
[WebMethod(Description="Retrieve the information for the given paste
part ID.")]
public TPastePart PastePart_Get(int PastePartID){
TPastePart PastePart = null;
ConnectionStringSettings Cs =
ConfigurationManager.ConnectionStrings["ECS"];

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

try{
SqlCmd.CommandText = "ccisp_PastePart_Get";
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Connection = SqlCon;
SqlCmd.Parameters.Add(new SqlParameter("@RETURN_VALUE",
SqlDbType.Int,
4,

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

SqlCmd.Parameters.Add(new SqlParameter("@PastePartID",
SqlDbType.Int,
4,
ParameterDirection.Input,
false,
((System.Byte)(10)),
((System.Byte)(0)),
"",
DataRowVersion.Current,
PastePartID));

SqlCon.ConnectionString = (string)Cs.ConnectionString;
SqlCon.Open();
SqlReader = SqlCmd.ExecuteReader();

if(SqlReader.HasRows){
SqlReader.Read();

PastePart = new TPastePart(SqlReader.GetInt32(0), //
PastePartID
SqlReader.GetString(1), //
PastePartNumber
SqlReader.GetString(2), //
PastePartDescription
SqlReader.GetString(3)); //PastePart
}//END IF-STATEMENT "if(SqlReader.HasRows)"
}//END TRY-BLOCK
catch(Exception E){
HandleWebException(E);
}//END CATCH-BLOCK
finally{
SqlCon.Close();
}//END FINALLY-BLOCK

return(PastePart);
}

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

//WITH "set" ACCESSOR
METHOD********************************************
<TPastePart>
<PastePartID>1</PastePartID>
<PastePart>46-141 7% Platinum Paste</PastePart>
<PastePartNumber>46-141</PastePartNumber>
<PastePartDescription>7% Platinum Paste</PastePartDescription>
<PasteViscosityID>1</PasteViscosityID>
</TPastePart>
//
************************************************** ********************

//WITH OUT "set" ACCESSOR METHOD
***************************************
<TPastePart>
<PastePartNumber>46-141</PastePartNumber>
<PastePartDescription>7% Platinum Paste</PastePartDescription>
<PasteViscosityID>1</PasteViscosityID>
</TPastePart>
//
************************************************** ********************
Oct 30 '07 #3

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

Similar topics

2
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...
3
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...
4
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...
1
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...
12
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...
3
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
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...
0
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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,...
0
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...

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.