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

Home Posts Topics Members FAQ

Reflection on instance returned from W/Service

Hi y'all ...

I've just come across a rather weird problem.

i'm using the following code to get the names of the public properties of an
object:

public static string[] GetPropertyNames(object instance){
Type objType = instance.GetType();
PropertyInfo[] props = objType.GetProperties();
string[] strPropNames = new string[props.Length];
for(int i=0; i<props.Length; i++)
strPropNames[i] = props[i].Name;
return strPropNames;
}

... that worked fine on framework class instances, and it also worked on my
own classes, even after I'd loaded an assembly dynamically from the file
system.

HOWEVER, now I'm using it to query an instance of a class returned from a
web service. I know that the class has several public properties [duh! I
wrote it !], but the code above doesn't work. It returns a zero-length
string array. A similar function that returns the method names, returns the
classic "object" methods, which is again not correct [quering for the method
names should also return the "get_<public property name>" methods for each
public property ... ]

Does anyone have a clue on what might be happening here ??? Did i mention
that querying the Type name of the instance returns the class name in the
namespace created by VS for the Web Reference ? [ as it should ]

Cheers,
Angel
O:]
Jul 21 '05 #1
3 1596
Angelos Karantzalis <ak**********@yahoo.com> wrote:
I've just come across a rather weird problem.

i'm using the following code to get the names of the public properties of an
object:

public static string[] GetPropertyNames(object instance){
Type objType = instance.GetType();
PropertyInfo[] props = objType.GetProperties();
string[] strPropNames = new string[props.Length];
for(int i=0; i<props.Length; i++)
strPropNames[i] = props[i].Name;
return strPropNames;
}

.. that worked fine on framework class instances, and it also worked on my
own classes, even after I'd loaded an assembly dynamically from the file
system.

HOWEVER, now I'm using it to query an instance of a class returned from a
web service. I know that the class has several public properties [duh! I
wrote it !], but the code above doesn't work. It returns a zero-length
string array. A similar function that returns the method names, returns the
classic "object" methods, which is again not correct [quering for the method
names should also return the "get_<public property name>" methods for each
public property ... ]

Does anyone have a clue on what might be happening here ??? Did i mention
that querying the Type name of the instance returns the class name in the
namespace created by VS for the Web Reference ? [ as it should ]


I *believe* that types returned by web services don't have properties -
they just have public fields. Look at the code VS generated for you for
the type to check.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
The objects created by Visual Studio doesn't have properties, it only has
public fields.
You'll either have to change your reflection code to access these fields or
you will have create your own proxy using the WSDL tool and then change the
code to use properties instead.

Anders Norås
blog: http://dotnetjunkies.com/weblog/anoras

"Angelos Karantzalis" <ak**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi y'all ...

I've just come across a rather weird problem.

i'm using the following code to get the names of the public properties of
an
object:

public static string[] GetPropertyNames(object instance){
Type objType = instance.GetType();
PropertyInfo[] props = objType.GetProperties();
string[] strPropNames = new string[props.Length];
for(int i=0; i<props.Length; i++)
strPropNames[i] = props[i].Name;
return strPropNames;
}

.. that worked fine on framework class instances, and it also worked on my
own classes, even after I'd loaded an assembly dynamically from the file
system.

HOWEVER, now I'm using it to query an instance of a class returned from a
web service. I know that the class has several public properties [duh! I
wrote it !], but the code above doesn't work. It returns a zero-length
string array. A similar function that returns the method names, returns
the
classic "object" methods, which is again not correct [quering for the
method
names should also return the "get_<public property name>" methods for each
public property ... ]

Does anyone have a clue on what might be happening here ??? Did i mention
that querying the Type name of the instance returns the class name in the
namespace created by VS for the Web Reference ? [ as it should ]

Cheers,
Angel
O:]

Jul 21 '05 #3
god .. how could I be so stupid & not check for public fields ... ? That was
it allright ...

Thanks a milion guys, i guess sometimes technology IS a substitute for
stupidity :D

O:]

"Anders Norås" <an**********@objectware.no> wrote in message
news:#6**************@TK2MSFTNGP10.phx.gbl...
The objects created by Visual Studio doesn't have properties, it only has
public fields.
You'll either have to change your reflection code to access these fields or you will have create your own proxy using the WSDL tool and then change the code to use properties instead.

Anders Norås
blog: http://dotnetjunkies.com/weblog/anoras

"Angelos Karantzalis" <ak**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi y'all ...

I've just come across a rather weird problem.

i'm using the following code to get the names of the public properties of an
object:

public static string[] GetPropertyNames(object instance){
Type objType = instance.GetType();
PropertyInfo[] props = objType.GetProperties();
string[] strPropNames = new string[props.Length];
for(int i=0; i<props.Length; i++)
strPropNames[i] = props[i].Name;
return strPropNames;
}

.. that worked fine on framework class instances, and it also worked on my own classes, even after I'd loaded an assembly dynamically from the file
system.

HOWEVER, now I'm using it to query an instance of a class returned from a web service. I know that the class has several public properties [duh! I
wrote it !], but the code above doesn't work. It returns a zero-length
string array. A similar function that returns the method names, returns
the
classic "object" methods, which is again not correct [quering for the
method
names should also return the "get_<public property name>" methods for each public property ... ]

Does anyone have a clue on what might be happening here ??? Did i mention that querying the Type name of the instance returns the class name in the namespace created by VS for the Web Reference ? [ as it should ]

Cheers,
Angel
O:]


Jul 21 '05 #4

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

Similar topics

2
by: Steve | last post by:
Hi all If there is a more relevant NG for my question about Reflection I would be grateful if some-one could point me in the right direction! I am using the following code to get the Public...
2
by: Lev | last post by:
Hi, I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the MC++ version does not return anything....
0
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
2
by: Marco | last post by:
Hi, I try to use reflection to retrieve class B members and not inherited members. I wonder why the myMember value is nothing. Any suggestions? Thanks Module Module1 Sub Main()
6
by: ECathell | last post by:
I have a routine that compares 2 intances of the same object to see if there are any changes. The problem is that even though there are no changes, it tells me there are. I have even tried running a...
3
by: Angelos Karantzalis | last post by:
Hi y'all ... I've just come across a rather weird problem. i'm using the following code to get the names of the public properties of an object: public static string GetPropertyNames(object...
15
by: satankidneypie | last post by:
Hi, I'm going to start this off with some code as it'll make it easier to explain afterwards... using System; namespace ConsoleApplication1 { /// <summary>
9
by: TS | last post by:
i have code that creates assemblies and classes from the assemlby and methods from the classes to set properties of dynamically created controls. How i should go about validating the assemblies,...
3
by: Steve Amey | last post by:
Hi all I am using reflection to read the values of properties from a class. The class is returned from a Web Service so I have to access the class using FieldInfo (Using VS 2003 which converts...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
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.