473,661 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning different types of objects in a column in a dataset

For a WebService I am developing, I return a DataSet that contains a
table listing Field Names and Field Values. The FieldValue column is
given the type object becuase it can potentially contain any of the
primative value types (date, int, decimal, string, bool, etc).
However, when my client consumes the webservice, it is always a string,
even if the value wasn't a string when it was put into the dataset.
How do I return different types of objects in the same column of a
dataset, and get a client to recognize it?

Thanks!

Nov 23 '05 #1
8 2338
"Myron Marston" <gu***********@ hotmail.com> wrote in
news:11******** *************@o 13g2000cwo.goog legroups.com:
For a WebService I am developing, I return a DataSet that contains a
table listing Field Names and Field Values. The FieldValue column is
given the type object becuase it can potentially contain any of the
primative value types (date, int, decimal, string, bool, etc).
However, when my client consumes the webservice, it is always a string,
even if the value wasn't a string when it was put into the dataset.
How do I return different types of objects in the same column of a
dataset, and get a client to recognize it?


Web services cannot return objects. Objects are not "portable". So whats
happening is its serializing it, and for the object that you are searlizing
thats whats happening.

You can convert each one to a string (ToString or so) and then reparse on the
other side.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #2
It appears that Web services can return objects. I wrote a test
webservice that returns an object based on the parameter, and my client
recognized it correctly. Here is the code that works:

<WebMethod()> _
Public Function GetObject(ByVal ObjectType As String) As Object
Select Case ObjectType
Case "Date"
Return Date.Today
Case "Int"
Return 23
Case "Decimal"
Return 23.34534D
Case "Bool"
Return False
Case Else
Return New Object
End Select
End Function

However, when I try to stuff an object in a column in a datatable and
return the dataset, this fails. Here is some test code for that:

<WebMethod()> _
Public Function GetDataSet(ByVa l ObjectType As String) As DataSet
Dim ds As New DataSet
Dim dt As DataTable = ds.Tables.Add(" Test")
dt.Columns.Add( "Object", GetType(Object) )
Dim dr As DataRow = dt.NewRow
dr("Object") = GetObject(Objec tType)
dt.Rows.Add(dr)
Return ds
End Function

So, is this only a problem with datasets?

Nov 23 '05 #3
"Myron Marston" <gu***********@ hotmail.com> wrote in
news:11******** **************@ g14g2000cwa.goo glegroups.com:
It appears that Web services can return objects. I wrote a test
No, it cant. Webservcies can return VALUE types, or objects that can
convert themselves to strings. That is very different.
<WebMethod() > _
Public Function GetObject(ByVal ObjectType As String) As Object
Select Case ObjectType
Case "Date"
Return Date.Today
Case "Int"
Return 23
Case "Decimal"
Return 23.34534D
Case "Bool"
Return False
Case Else
Return New Object
End Select
End Function
Thats not returning an object.
However, when I try to stuff an object in a column in a datatable and
return the dataset, this fails. Here is some test code for that:
Yes, because as I said above you are NOT returning an object as you think.
So, is this only a problem with datasets?


No, the problem is with your understanding of whats going on. Webservices
CANNOT return objects.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #4
I understand the difference between value types and reference types.
Maybe I haven't been using the term "object" in a clear manner, but all
value types are objects (after all, System.ValueTyp e derives from
System.Object, and Int32, DateTime, etc derive from System.ValueTyp e).
Of course the webservice does not return the entire object but only a
serialized xml version of it that is deserialized into the
corresponding type on the client.

Still, my question remains: why does it work for the value type to be
correctly recognized by the client in the first example (where it was
only returning a single value) but not in the second example (where it
returned the value inside of a dataset)?

Nov 23 '05 #5
"Myron Marston" <gu***********@ hotmail.com> wrote in
news:11******** *************@o 13g2000cwo.goog legroups.com:
For a WebService I am developing, I return a DataSet that contains a
table listing Field Names and Field Values. The FieldValue column is
given the type object becuase it can potentially contain any of the
primative value types (date, int, decimal, string, bool, etc).
However, when my client consumes the webservice, it is always a string,
even if the value wasn't a string when it was put into the dataset.
How do I return different types of objects in the same column of a
dataset, and get a client to recognize it?


Web services cannot return objects. Objects are not "portable". So whats
happening is its serializing it, and for the object that you are searlizing
thats whats happening.

You can convert each one to a string (ToString or so) and then reparse on the
other side.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #6
It appears that Web services can return objects. I wrote a test
webservice that returns an object based on the parameter, and my client
recognized it correctly. Here is the code that works:

<WebMethod()> _
Public Function GetObject(ByVal ObjectType As String) As Object
Select Case ObjectType
Case "Date"
Return Date.Today
Case "Int"
Return 23
Case "Decimal"
Return 23.34534D
Case "Bool"
Return False
Case Else
Return New Object
End Select
End Function

However, when I try to stuff an object in a column in a datatable and
return the dataset, this fails. Here is some test code for that:

<WebMethod()> _
Public Function GetDataSet(ByVa l ObjectType As String) As DataSet
Dim ds As New DataSet
Dim dt As DataTable = ds.Tables.Add(" Test")
dt.Columns.Add( "Object", GetType(Object) )
Dim dr As DataRow = dt.NewRow
dr("Object") = GetObject(Objec tType)
dt.Rows.Add(dr)
Return ds
End Function

So, is this only a problem with datasets?

Nov 23 '05 #7
"Myron Marston" <gu***********@ hotmail.com> wrote in
news:11******** **************@ g14g2000cwa.goo glegroups.com:
It appears that Web services can return objects. I wrote a test
No, it cant. Webservcies can return VALUE types, or objects that can
convert themselves to strings. That is very different.
<WebMethod() > _
Public Function GetObject(ByVal ObjectType As String) As Object
Select Case ObjectType
Case "Date"
Return Date.Today
Case "Int"
Return 23
Case "Decimal"
Return 23.34534D
Case "Bool"
Return False
Case Else
Return New Object
End Select
End Function
Thats not returning an object.
However, when I try to stuff an object in a column in a datatable and
return the dataset, this fails. Here is some test code for that:
Yes, because as I said above you are NOT returning an object as you think.
So, is this only a problem with datasets?


No, the problem is with your understanding of whats going on. Webservices
CANNOT return objects.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Nov 23 '05 #8
I understand the difference between value types and reference types.
Maybe I haven't been using the term "object" in a clear manner, but all
value types are objects (after all, System.ValueTyp e derives from
System.Object, and Int32, DateTime, etc derive from System.ValueTyp e).
Of course the webservice does not return the entire object but only a
serialized xml version of it that is deserialized into the
corresponding type on the client.

Still, my question remains: why does it work for the value type to be
correctly recognized by the client in the first example (where it was
only returning a single value) but not in the second example (where it
returned the value inside of a dataset)?

Nov 23 '05 #9

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

Similar topics

1
2197
by: Craig | last post by:
Hi, I am storing information being sent to me weekly into a ms sql database. The one twist I am running into is that later down the line the information I recieve may require more columns, or columns might be renamed so having a static database call is out of the question. I was using mysql but for certain reasons switched to ms sql 2000. Currently before ms sql, I query the database for show fields which returns all the database data such...
7
2190
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from another. I have tried declaring them as shared, public, friend, etc and I always get an error stating that something is not valid on a local variable declaration. For example, in the following code for Sub DataGrid_Select, I have CurrentID and...
6
13407
by: Scott M. Lyon | last post by:
As I mentioned in my other post, I'm attempting to, using COM Interop so I can update existing VB6 code to (for several specific functions) return a Hashtable from a .NET library. I've had very little luck processing the Hashtable itself in VB6 (I can add a reference to the project so it knows what a Hashtable is, but I'm not having much luck looping through all objects in the Hashtable), so I decided to try a different idea.
1
5545
by: J. Askey | last post by:
I am implementing a web service and thought it may be a good idea to return a more complex class (which I have called 'ServiceResponse') in order to wrap the original return value along with two other properties... bool error; string lastError; My whole class looks like this... using System;
0
1399
by: Larry Lard | last post by:
There seems to be something a bit lacking in the way the dataset designer thing deals (or rather doesn't) with nullable fields in VS2005. Maybe it's cos I'm using VB2005 Express (which is variously crippled), I don't know. But it seems to me obvious that there should be some way to specify that DB fields which can be null should be mapped to appropriate Nullable(Of T) generic types. For fields there's a dropdown in the dataset designer...
0
1528
by: TMesh | last post by:
Hello Is it possible to return a Crystal ReportDocument from a WebService? I keep getting the following error: Exception: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---System.InvalidOperationException: There was an error generating the XML document. ---System.InvalidOperationException: The type CrystalDecisions.CrystalReports.Engine.ReportDocument was not expected. Use
0
1768
by: Maart_newbie | last post by:
Hi all, I've got a question about returning the value of a pk-column to a DataTable after inserting a row (via a data-adapter) using MySql5. Here is the SQL and code concerned: //=================================================================== // The table
2
1569
by: David++ | last post by:
Hello list, I have built a project in VS2005 which includes a Web Service Web Site. On this server there is a Database. I have used the DataSet designer to link to this database and VS2005 has created Table Adapters which connect to the database and return the table data. My DataSet is called DatabaseDataSet. My WebMethod for returning data from the server database is as follows - public DataSet GetUserJobs(string id)
2
1356
by: Andy B | last post by:
I need to make a class and not quite sure how to go about doing this part. I want the class to take user input, build a dataset based on that input and then return it from the class so it can be used elsewhere. A few things about the dataset and the class that builds the dataset: 1. The dataset should already have prebuilt tables and columns that need to be filled in like Header, Sections, Glossary, FormHeader, Contacts and FormFooter....
0
8341
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
8851
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
8542
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
8630
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
6181
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
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
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
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
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.