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?
> 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)?