473,237 Members | 1,361 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,237 software developers and data experts.

Help with returning a C# object from a web service

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
4 1534
"rbjorkquist" <rb*********@coilcraft.comwrote in message
news:11**********************@q5g2000prf.googlegro ups.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?
You've found it. Add the setter.

This is a requirement of XML serialization. You'd have to ask Microsoft why
they require it.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer
Oct 17 '07 #2
On Oct 17, 12:52 pm, "John Saunders [MVP]" <john.saunders at
trizetto.comwrote:
"rbjorkquist" <rbjorkqu...@coilcraft.comwrote in message

news:11**********************@q5g2000prf.googlegro ups.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?

You've found it. Add the setter.

This is a requirement of XML serialization. You'd have to ask Microsoft why
they require it.
--
---------------------------------------------------------------------------*-----
John Saunders | MVP - Windows Server System - Connected System Developer
Hey John,

Thanks for the quick response. But just to make sure I'm
understanding what you are saying. Just add a blank setter method,
like I'm doing is ok? There will be no ill side affects? And, why if
I leave it blank, does it know how to give me the rest of the data? I
mean, I'm not telling it or doing anything special. Actually, I'm not
doing anything.

Thanks again,

Randel

Oct 17 '07 #3
"rbjorkquist" <rb*********@coilcraft.comwrote in message
news:11*********************@t8g2000prg.googlegrou ps.com...
On Oct 17, 12:52 pm, "John Saunders [MVP]" <john.saunders at
trizetto.comwrote:
"rbjorkquist" <rbjorkqu...@coilcraft.comwrote in message

news:11**********************@q5g2000prf.googlegro ups.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?

You've found it. Add the setter.

This is a requirement of XML serialization. You'd have to ask Microsoft
why
they require it.
--
---------------------------------------------------------------------------*-----
John Saunders | MVP - Windows Server System - Connected System Developer
Hey John,

Thanks for the quick response. But just to make sure I'm
understanding what you are saying. Just add a blank setter method,
like I'm doing is ok? There will be no ill side affects? And, why if
I leave it blank, does it know how to give me the rest of the data? I
mean, I'm not telling it or doing anything special. Actually, I'm not
doing anything.
----------
Yes, just leave a blank setter. This is just a restriction of the
serializer. As long as you don't need to deserialize that type, you'll be ok
with a setter that does nothing.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer
Oct 23 '07 #4
rbjorkquist <rb*********@coilcraft.comwrote in
news:11*********************@t8g2000prg.googlegrou ps.com:
Thanks for the quick response. But just to make sure I'm
understanding what you are saying. Just add a blank setter method,
like I'm doing is ok? There will be no ill side affects? And, why if
I leave it blank, does it know how to give me the rest of the data? I
mean, I'm not telling it or doing anything special. Actually, I'm not
doing anything.
You can even set the set to private...

As long as you're not serializing the object BACK to the server, I believe
you can have a private settor.

BTW, were you a Delphi programmer previously?
Oct 23 '07 #5

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

Similar topics

1
by: Liza | last post by:
Hi guys, i'm trying to build a web service....... is there such thing as polymorphism in web services? i mean could i have two web services of the same name but different arguments such that i...
0
by: Diego F. | last post by:
I've been days with that. I'm trying to work with web services sending and returning objects, and the web service must store some objects. - My first try (the most obvious in my opinion) was to use...
0
by: Arthur Mnev | last post by:
I'm a little confused about autogenerated proxy stubs for web services. Creating the stubs manually works fine; if I attempt to use "Web Reference" with automatic class generation the framwork (or...
5
by: LS | last post by:
Can a WebMethod return an Interface type? Can we pass an interface parameter ? Example : public interface IEntity { long Id { get; set; } string Name { get; set; } }
1
by: Matthias De Ridder | last post by:
Hello, I really hope that someone will be able to help me, because I'm desperate now! I'm a student, graduating this year, and I'm working on a thesis where C# Web Services are involved. I...
2
by: Ken Crismon | last post by:
Hello, I am currently working on an embedded systems project where by I have written a small web server that is being hosted on our internet appliance (running on an Atmega128 chip and doing...
5
by: Jim Murphy | last post by:
In creating a C# web service, I am having trouble returning a DataTable object as the result of a web method. I have no problem returning native types like string or int, but cannot return a .NET...
15
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 ...
5
by: Frank Hauptlorenz | last post by:
Hello, I recognized some days ago, that returning a DataTable blocks my WCF-Service. Is this a known bug? If I add this table to a new DataSet() and return this, it works. Thank you, Frank
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.