Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / May 2005

Tip: Looking for answers? Try searching our database.

Returning different types of objects in a column in a dataset

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Myron Marston - 18 May 2005 15:59 GMT
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!
Chad Z. Hower aka Kudzu - 18 May 2005 18:53 GMT
> For a WebService I am developing, I return a DataSet that contains a
> table listing Field Names and Field Values.  The FieldValue column is
[quoted text clipped - 4 lines]
> 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
Myron Marston - 18 May 2005 20:01 GMT
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?
Chad Z. Hower aka Kudzu - 19 May 2005 05:39 GMT
> 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
[quoted text clipped - 11 lines]
>         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
Myron Marston - 19 May 2005 16:25 GMT
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)?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.