473,486 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Databinding Marshalled Data From WebService

I have a web service which returns a collection of class object (see below).
I want to consume this service in another web application by binding it to a
List control The data returns from the web service, however when I bind
the data I get the following error
****
DataBinder.Eval: 'UserServices.User' does not contain a property with the
name FirstName.
****
Debugging I see that the list controls data source is a System.Array with
all of my data; each array element does indeed have an object with the
correct properties and FirstName is a public property/string. What am I
missing?

Brad

(cross posted to microsoft.public.dotnet.framework.aspnet
&
microsoft.public.dotnet.framework.aspnet.webservic es
)
Code examples
==================================
Web Service (example only...real code is more and pulls data from database)
==================================
Public Class User
Public UserID as integer
Public FirstName as string
End class

Public Class UserServices
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetUsers(ByVal appName As String) As User()
Dim myUsers(1) as New User
Dim userA as New User
userA.UserID = 1
userA.FirstName = "Fred"
myUsers(0) = userA

Dim userB as New User
userB.UserID = 2
userB.FirstName = "Barney"
myUsers(1) = userB
return myUsers
End Function
==================================
Consumer code
==================================

Dim svc As New Services.UserServices
Dim ui() As svc.UserInfo = ps.GetUsers()
UserList.DataTextField = "FirstName"
UserList.DataValueField = "UserID"
UserList.DataSource = ui
UserList.DataBind()
Nov 18 '05 #1
6 1325
Hi Brad,

You need to set "UserID" and "FirstName" as Property, not a field. For
example:

Public Class MyUser

Private _UserID As Integer
Private _FirstName As Integer

Public Property UserID() As Integer
Get
Return _UserID
End Get
Set(ByVal Value As Integer)
_UserID = Value
End Set
End Property
Public Property FirstName() As String
Get
Return _FirstName
End Get
Set(ByVal Value As String)

_FirstName = Value
End Set
End Property

End Class

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
Hi,

Actually Luke is right. You can't bind to public fields, only to public
properties. The proxy classes generated by VS.NET have public fields, so you
can't bind to them. BUT there is a solution for this. I've built a wrapper
class the transforms public fields into propeties at runtime. Actually I've
written an article about this problem which you can find here:
http://www.microsoft.com/belux/nl/ms...cewrapper.mspx
The data binding capabilities in .NET are great, you can bind many controls
to almost any type of data, but in some scenarios data binding has its
limitations. For example data binding is not possible when using custom
collections, instead of DataSets, coming from a Web Service. This article
explains the problem and a possible, easy-to-use, solution: a class that
dynamically builds wrapper classes at run time, which exposes the field
member of the proxy classes as properties.

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Brad" <no****@co.lane.or.us> schreef in bericht
news:en**************@TK2MSFTNGP11.phx.gbl...
I have a web service which returns a collection of class object (see below). I want to consume this service in another web application by binding it to a List control The data returns from the web service, however when I bind
the data I get the following error
****
DataBinder.Eval: 'UserServices.User' does not contain a property with the
name FirstName.
****
Debugging I see that the list controls data source is a System.Array with
all of my data; each array element does indeed have an object with the
correct properties and FirstName is a public property/string. What am I
missing?

Brad

(cross posted to microsoft.public.dotnet.framework.aspnet
&
microsoft.public.dotnet.framework.aspnet.webservic es
)
Code examples
==================================
Web Service (example only...real code is more and pulls data from database) ==================================
Public Class User
Public UserID as integer
Public FirstName as string
End class

Public Class UserServices
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetUsers(ByVal appName As String) As User()
Dim myUsers(1) as New User
Dim userA as New User
userA.UserID = 1
userA.FirstName = "Fred"
myUsers(0) = userA

Dim userB as New User
userB.UserID = 2
userB.FirstName = "Barney"
myUsers(1) = userB
return myUsers
End Function
==================================
Consumer code
==================================

Dim svc As New Services.UserServices
Dim ui() As svc.UserInfo = ps.GetUsers()
UserList.DataTextField = "FirstName"
UserList.DataValueField = "UserID"
UserList.DataSource = ui
UserList.DataBind()

Nov 18 '05 #3
Great article, Jan. It clearly explains what and why. Thank you.

Brad

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
Hi,

Actually Luke is right. You can't bind to public fields, only to public
properties. The proxy classes generated by VS.NET have public fields, so you can't bind to them. BUT there is a solution for this. I've built a wrapper
class the transforms public fields into propeties at runtime. Actually I've written an article about this problem which you can find here:
http://www.microsoft.com/belux/nl/ms...cewrapper.mspx The data binding capabilities in .NET are great, you can bind many controls to almost any type of data, but in some scenarios data binding has its
limitations. For example data binding is not possible when using custom
collections, instead of DataSets, coming from a Web Service. This article
explains the problem and a possible, easy-to-use, solution: a class that
dynamically builds wrapper classes at run time, which exposes the field
member of the proxy classes as properties.

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Brad" <no****@co.lane.or.us> schreef in bericht
news:en**************@TK2MSFTNGP11.phx.gbl...
I have a web service which returns a collection of class object (see below).
I want to consume this service in another web application by binding it to a
List control The data returns from the web service, however when I

bind the data I get the following error
****
DataBinder.Eval: 'UserServices.User' does not contain a property with the name FirstName.
****
Debugging I see that the list controls data source is a System.Array with all of my data; each array element does indeed have an object with the
correct properties and FirstName is a public property/string. What am I missing?

Brad

(cross posted to microsoft.public.dotnet.framework.aspnet
&
microsoft.public.dotnet.framework.aspnet.webservic es
)
Code examples
==================================
Web Service (example only...real code is more and pulls data from

database)
==================================
Public Class User
Public UserID as integer
Public FirstName as string
End class

Public Class UserServices
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetUsers(ByVal appName As String) As User()
Dim myUsers(1) as New User
Dim userA as New User
userA.UserID = 1
userA.FirstName = "Fred"
myUsers(0) = userA

Dim userB as New User
userB.UserID = 2
userB.FirstName = "Barney"
myUsers(1) = userB
return myUsers
End Function
==================================
Consumer code
==================================

Dim svc As New Services.UserServices
Dim ui() As svc.UserInfo = ps.GetUsers()
UserList.DataTextField = "FirstName"
UserList.DataValueField = "UserID"
UserList.DataSource = ui
UserList.DataBind()


Nov 18 '05 #4
Or more easily just use a tool that automatically can generate the code you
need:
http://www.gotdotnet.com/Community/U...f-e001fac664a6
No need for wsdl.exe or Web Reference (only caveat for some users currently
is that the WSDL has to be present locally).

Cheers,
--
Christian Weyer
[Microsoft Regional Director, Germany]
[MVP ASP.NET & XML Web Services]

** XML Web Services: http://www.xmlwebservices.cc/
** Weblog: http://weblogs.asp.net/cweyer/

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
Hi,

Actually Luke is right. You can't bind to public fields, only to public
properties. The proxy classes generated by VS.NET have public fields, so you can't bind to them. BUT there is a solution for this. I've built a wrapper
class the transforms public fields into propeties at runtime. Actually I've written an article about this problem which you can find here:
http://www.microsoft.com/belux/nl/ms...cewrapper.mspx The data binding capabilities in .NET are great, you can bind many controls to almost any type of data, but in some scenarios data binding has its
limitations. For example data binding is not possible when using custom
collections, instead of DataSets, coming from a Web Service. This article
explains the problem and a possible, easy-to-use, solution: a class that
dynamically builds wrapper classes at run time, which exposes the field
member of the proxy classes as properties.

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Brad" <no****@co.lane.or.us> schreef in bericht
news:en**************@TK2MSFTNGP11.phx.gbl...
I have a web service which returns a collection of class object (see below).
I want to consume this service in another web application by binding it to a
List control The data returns from the web service, however when I

bind the data I get the following error
****
DataBinder.Eval: 'UserServices.User' does not contain a property with the name FirstName.
****
Debugging I see that the list controls data source is a System.Array with all of my data; each array element does indeed have an object with the
correct properties and FirstName is a public property/string. What am I missing?

Brad

(cross posted to microsoft.public.dotnet.framework.aspnet
&
microsoft.public.dotnet.framework.aspnet.webservic es
)
Code examples
==================================
Web Service (example only...real code is more and pulls data from

database)
==================================
Public Class User
Public UserID as integer
Public FirstName as string
End class

Public Class UserServices
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetUsers(ByVal appName As String) As User()
Dim myUsers(1) as New User
Dim userA as New User
userA.UserID = 1
userA.FirstName = "Fred"
myUsers(0) = userA

Dim userB as New User
userB.UserID = 2
userB.FirstName = "Barney"
myUsers(1) = userB
return myUsers
End Function
==================================
Consumer code
==================================

Dim svc As New Services.UserServices
Dim ui() As svc.UserInfo = ps.GetUsers()
UserList.DataTextField = "FirstName"
UserList.DataValueField = "UserID"
UserList.DataSource = ui
UserList.DataBind()


Nov 18 '05 #5
Hi Christian

I saw your tool on your blog some time ago, nice work man! Do you have any
idea why MS implemented public fields instead of public properties on proxy
classes? I tested this in Whidbey, and there is still the same behaviour...
:-/

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Christian Weyer" <cw@no.spam_eyesoft_sucks.de> schreef in bericht
news:OL**************@TK2MSFTNGP09.phx.gbl...
Or more easily just use a tool that automatically can generate the code you need:
http://www.gotdotnet.com/Community/U...f-e001fac664a6 No need for wsdl.exe or Web Reference (only caveat for some users currently is that the WSDL has to be present locally).

Cheers,
--
Christian Weyer
[Microsoft Regional Director, Germany]
[MVP ASP.NET & XML Web Services]

** XML Web Services: http://www.xmlwebservices.cc/
** Weblog: http://weblogs.asp.net/cweyer/

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
Hi,

Actually Luke is right. You can't bind to public fields, only to public
properties. The proxy classes generated by VS.NET have public fields, so you
can't bind to them. BUT there is a solution for this. I've built a wrapper
class the transforms public fields into propeties at runtime. Actually

I've
written an article about this problem which you can find here:

http://www.microsoft.com/belux/nl/ms...cewrapper.mspx
The data binding capabilities in .NET are great, you can bind many

controls
to almost any type of data, but in some scenarios data binding has its
limitations. For example data binding is not possible when using custom
collections, instead of DataSets, coming from a Web Service. This article explains the problem and a possible, easy-to-use, solution: a class that
dynamically builds wrapper classes at run time, which exposes the field
member of the proxy classes as properties.

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Brad" <no****@co.lane.or.us> schreef in bericht
news:en**************@TK2MSFTNGP11.phx.gbl...
I have a web service which returns a collection of class object (see

below).
I want to consume this service in another web application by binding

it to
a
List control The data returns from the web service, however when I
bind the data I get the following error
****
DataBinder.Eval: 'UserServices.User' does not contain a property with the name FirstName.
****
Debugging I see that the list controls data source is a System.Array with all of my data; each array element does indeed have an object with the
correct properties and FirstName is a public property/string. What
am I missing?

Brad

(cross posted to microsoft.public.dotnet.framework.aspnet
&
microsoft.public.dotnet.framework.aspnet.webservic es
)
Code examples
==================================
Web Service (example only...real code is more and pulls data from

database)
==================================
Public Class User
Public UserID as integer
Public FirstName as string
End class

Public Class UserServices
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetUsers(ByVal appName As String) As User()
Dim myUsers(1) as New User
Dim userA as New User
userA.UserID = 1
userA.FirstName = "Fred"
myUsers(0) = userA

Dim userB as New User
userB.UserID = 2
userB.FirstName = "Barney"
myUsers(1) = userB
return myUsers
End Function
==================================
Consumer code
==================================

Dim svc As New Services.UserServices
Dim ui() As svc.UserInfo = ps.GetUsers()
UserList.DataTextField = "FirstName"
UserList.DataValueField = "UserID"
UserList.DataSource = ui
UserList.DataBind()



Nov 18 '05 #6
Hi Jan,

hm, AFAIK, it then was just a matter of time (and not thinking enough about
the problem space?) - but I guess they will support public properties in the
Beta. Actually it is just three lines of code they have to change ;-)

Cheers,
--
Christian Weyer
[Microsoft Regional Director, Germany]
[MVP ASP.NET & XML Web Services]

** XML Web Services: http://www.xmlwebservices.cc/
** Weblog: http://weblogs.asp.net/cweyer/

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:#u**************@TK2MSFTNGP10.phx.gbl...
Hi Christian

I saw your tool on your blog some time ago, nice work man! Do you have any
idea why MS implemented public fields instead of public properties on proxy classes? I tested this in Whidbey, and there is still the same behaviour... :-/

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Christian Weyer" <cw@no.spam_eyesoft_sucks.de> schreef in bericht
news:OL**************@TK2MSFTNGP09.phx.gbl...
Or more easily just use a tool that automatically can generate the code

you
need:

http://www.gotdotnet.com/Community/U...f-e001fac664a6
No need for wsdl.exe or Web Reference (only caveat for some users

currently
is that the WSDL has to be present locally).

Cheers,
--
Christian Weyer
[Microsoft Regional Director, Germany]
[MVP ASP.NET & XML Web Services]

** XML Web Services: http://www.xmlwebservices.cc/
** Weblog: http://weblogs.asp.net/cweyer/

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
Hi,

Actually Luke is right. You can't bind to public fields, only to public properties. The proxy classes generated by VS.NET have public fields, so
you
can't bind to them. BUT there is a solution for this. I've built a wrapper class the transforms public fields into propeties at runtime. Actually

I've
written an article about this problem which you can find here:

http://www.microsoft.com/belux/nl/ms...cewrapper.mspx The data binding capabilities in .NET are great, you can bind many

controls
to almost any type of data, but in some scenarios data binding has its
limitations. For example data binding is not possible when using custom collections, instead of DataSets, coming from a Web Service. This article explains the problem and a possible, easy-to-use, solution: a class that dynamically builds wrapper classes at run time, which exposes the field member of the proxy classes as properties.

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Brad" <no****@co.lane.or.us> schreef in bericht
news:en**************@TK2MSFTNGP11.phx.gbl...
> I have a web service which returns a collection of class object (see
below).
> I want to consume this service in another web application by binding it
to
a
> List control The data returns from the web service, however when I bind
> the data I get the following error
> ****
> DataBinder.Eval: 'UserServices.User' does not contain a property
with the
> name FirstName.
> ****
> Debugging I see that the list controls data source is a System.Array

with
> all of my data; each array element does indeed have an object with

the > correct properties and FirstName is a public property/string. What

am
I
> missing?
>
> Brad
>
> (cross posted to microsoft.public.dotnet.framework.aspnet
> &
> microsoft.public.dotnet.framework.aspnet.webservic es
> )
>
>
> Code examples
> ==================================
> Web Service (example only...real code is more and pulls data from
database)
> ==================================
> Public Class User
> Public UserID as integer
> Public FirstName as string
> End class
>
> Public Class UserServices
> Inherits System.Web.Services.WebService
> <WebMethod()> _
> Public Function GetUsers(ByVal appName As String) As User()
> Dim myUsers(1) as New User
> Dim userA as New User
> userA.UserID = 1
> userA.FirstName = "Fred"
> myUsers(0) = userA
>
> Dim userB as New User
> userB.UserID = 2
> userB.FirstName = "Barney"
> myUsers(1) = userB
> return myUsers
> End Function
>
>
> ==================================
> Consumer code
> ==================================
>
> Dim svc As New Services.UserServices
> Dim ui() As svc.UserInfo = ps.GetUsers()
> UserList.DataTextField = "FirstName"
> UserList.DataValueField = "UserID"
> UserList.DataSource = ui
> UserList.DataBind()
>
>



Nov 18 '05 #7

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

Similar topics

1
1942
by: Jeremy Ames | last post by:
Ok, so I am still trying to get use to ADO.Net, but I have come leaps and bounds to this point. I am trying to bind a dataset that I have returned from a webservice to a HtmlTable. It appears that...
7
11896
by: BS | last post by:
Hello everybody I'm calling a webservice that returns complex data. The goal is to populate a datagrid with it. Using a loop for each record found ( such as For i = 0 To...
3
7426
by: Dan Slaby | last post by:
I have a webservice that I want to populate a combobox on a windows form. The webservice creates the correct XML output, but when I attempt to bind it to a combobox I get this error: Additional...
8
2163
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
0
7100
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
7126
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,...
0
7175
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
7330
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...
0
5434
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
4865
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
4559
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
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
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 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.