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! 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
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?
"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
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)?
"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
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?
"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
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)? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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:
...
|
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...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |