By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,013 Members | 1,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,013 IT Pros & Developers. It's quick & easy.

Why do I need both, getter and setter accessor methods

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.