473,508 Members | 2,367 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 2329
"Myron Marston" <gu***********@hotmail.com> wrote in
news:11*********************@o13g2000cwo.googlegro ups.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/
"Programming 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(ByVal 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(ObjectType)
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.googlegr oups.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/
"Programming 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.ValueType derives from
System.Object, and Int32, DateTime, etc derive from System.ValueType).
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*********************@o13g2000cwo.googlegro ups.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/
"Programming 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(ByVal 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(ObjectType)
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.googlegr oups.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/
"Programming 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.ValueType derives from
System.Object, and Int32, DateTime, etc derive from System.ValueType).
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
2174
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...
7
2177
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...
6
13373
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...
1
5525
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...
0
1391
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...
0
1520
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...
0
1760
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: ...
2
1560
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...
2
1351
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...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7380
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...
0
5626
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,...
1
5050
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...
0
4706
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...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
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 ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.