473,614 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "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
4 1550
"rbjorkquis t" <rb*********@co ilcraft.comwrot e in message
news:11******** **************@ q5g2000prf.goog legroups.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?
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.saunder s at
trizetto.comwro te:
"rbjorkquis t" <rbjorkqu...@co ilcraft.comwrot e in message

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

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
"rbjorkquis t" <rb*********@co ilcraft.comwrot e in message
news:11******** *************@t 8g2000prg.googl egroups.com...
On Oct 17, 12:52 pm, "John Saunders [MVP]" <john.saunder s at
trizetto.comwro te:
"rbjorkquis t" <rbjorkqu...@co ilcraft.comwrot e in message

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

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*********@co ilcraft.comwrot e in
news:11******** *************@t 8g2000prg.googl egroups.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
1576
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 could construct the following use case Actor : WebServiceRequestor
0
2153
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 a class contained in a extern dll so the web service and the application can use it and send or return via web services: public customObject myWebMethod(customObject obj); . I saw that web services can't deal with this cause the WS creates...
0
980
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 VS.2003) will generate a proxy class for the web service, that class will contain half backed XML representation of classes the service is using (consuming or returning). Logically it seems fine at every step except Automatic Proxy generator is...
5
10365
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
2062
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 only have three weeks to finish it all! My GUI and Web services were finished, but I hadn't tested them. So I linked the GUI to the Web service and started testing them.
2
2575
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 lots of col RFID and Mesh network stuff). In this example I am trying to get the AuthenticateUser web service to work. I am using the following WSDL:
5
4965
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 DataTable object. The problem occurs when I try to compile the client side C# application (it complains about the DataTable type not being recognized as the return of the web service method). Thanks
15
13500
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 http://msdn2.microsoft.com/en-us/library/ms996381.aspx Formerly, with classic Microsoft DNA architecture, the ADO Recordset was a primary transport medium, recommended for transmitting data between application tiers. In fact, there are whole books written on the subject.
5
8630
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
0
8142
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
8642
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...
0
8591
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
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
8444
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...
1
6093
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
5549
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
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.