Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > webserve returning an object with List<T> not working

Reply
Thread Tools

webserve returning an object with List<T> not working

 
 
Rafia Tapia
Guest
Posts: n/a
 
      11-03-2008
Hi
I have defined the following object that is return by my web service
public class MyCustomObj
{
private string ObjID;
private string ObjTitle;
private List<ObjProperty> ObjProperties;

//The above private variables have the corresponding public
properties
}
public struct ObjProperty
{
public string PropertyName;
public string PropertyType;
public StringCollection PropertyValues;
}
when I invoke the web service through the browser, I see my object with all
of its properties including the type List<ObjProperty> but the object that
is returned to the client application does not show the values of the
variable defined in ObjProperty. In other words when I invoke the web
service I get the following xml returned to the brower

<MyCustomObj>
<ObjID>1</ObjID>
<ObjTitle>Web Title</ObjTitle>
<ObjProperties>
<ObjProperty>
<PropertyName>SEOEnabled</PropertyName>
<PropertyType>System.Boolean</PropertyType>
<PropertyValues>
<string>False</string>
</PropertyValues>
</ObjProperty>
<ObjProperty>
<PropertyName>Users</PropertyName>
<PropertyType>System.String</PropertyType>
<PropertyValues>
<string>Ben</string>
<string>John</string>
</PropertyValues>
</ObjProperty>
</ObjProperties>
</MyCustomObj>

but the object return to the client application has count of two for the
List<ObjProperties> variable but all the variables of each of the
ObjProperty is null. Can anyone please tell me what I am doing wrong.

Thanks


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      11-03-2008
"Rafia Tapia" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
> I have defined the following object that is return by my web service

....
> but the object return to the client application has count of two for the
> List<ObjProperties> variable but all the variables of each of the
> ObjProperty is null. Can anyone please tell me what I am doing wrong.


How was the client created? "Add Web Reference?". If so, then try building
the service, making sure it's started (right-click the .asmx file and use
"View in Browser"), then use the "Update Web Reference" command on the
client, build it and try again.

--
John Saunders | MVP - Connected System Developer

 
Reply With Quote
 
 
 
 
Steven Cheng
Guest
Posts: n/a
 
      11-04-2008
Hi Rafia,

As other guys has explained, you can run .NET 2.0 application in a .NET 3.5
environment without problems. This is because .NET 3.5(also .NET 3.0) is
built upon .NET 2.0, it rely on the .NET 2.0 clr engine and most
fundamental class library. In my opinion, .NET 3.0 and 3.5 is more like
some advanced pack on the .NET framework 2.0 which add more features(such
as the W*F in .NET 3.0 and the LINQ, AJAX in .NET 3.5)

For development consideration, the VS 2008 IDE support multi-target
projects(from .NET 2.0, .NET 30 to .NET 3.5). Therefore, you can develop
applications target different version of .NET framework.

#VS 2008 Multi-Targeting Support
http://weblogs.asp.net/scottgu/archi...i-targeting-su
pport.aspx

http://blogs.msdn.com/dajung/archive...ti-target-fram
eworks.aspx


In addition, you can read the following articles about more explanation on
the .NET 2.0 and .NET 3.X versioning:

http://blogs.msdn.com/zxue/archive/2...ramework-3-5-d
ifferent-from-net-2-0-and-net-3-0.aspx

http://blogs.msdn.com/johnmullinax/a...the-value-of-n
et-3-5-vs-net-2-0-well-that-depends-on-you.aspx

If you have any further specific questions, welcome to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: http://www.velocityreviews.com/forums/(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/en-us/subs...#notifications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: "Rafia Tapia" <(E-Mail Removed)>
>Subject: webserve returning an object with List<T> not working
>Date: Mon, 3 Nov 2008 09:56:07 -0500
>Hi
>I have defined the following object that is return by my web service
>public class MyCustomObj
> {
> private string ObjID;
> private string ObjTitle;
> private List<ObjProperty> ObjProperties;
>
> //The above private variables have the corresponding public
>properties
> }
>public struct ObjProperty
> {
> public string PropertyName;
> public string PropertyType;
> public StringCollection PropertyValues;
>}
>when I invoke the web service through the browser, I see my object with

all
>of its properties including the type List<ObjProperty> but the object that
>is returned to the client application does not show the values of the
>variable defined in ObjProperty. In other words when I invoke the web
>service I get the following xml returned to the brower
>
><MyCustomObj>
> <ObjID>1</ObjID>
> <ObjTitle>Web Title</ObjTitle>
> <ObjProperties>
> <ObjProperty>
> <PropertyName>SEOEnabled</PropertyName>
> <PropertyType>System.Boolean</PropertyType>
> <PropertyValues>
> <string>False</string>
> </PropertyValues>
> </ObjProperty>
> <ObjProperty>
> <PropertyName>Users</PropertyName>
> <PropertyType>System.String</PropertyType>
> <PropertyValues>
> <string>Ben</string>
> <string>John</string>
> </PropertyValues>
> </ObjProperty>
> </ObjProperties>
></MyCustomObj>
>
>but the object return to the client application has count of two for the
>List<ObjProperties> variable but all the variables of each of the
>ObjProperty is null. Can anyone please tell me what I am doing wrong.
>
>Thanks
>
>
>


 
Reply With Quote
 
Steven Cheng
Guest
Posts: n/a
 
      11-04-2008
Hi Rafia,

Sorry for the previous incorrect message, it was a wrong post.

Regarding on the problem you mentioned here, I've also performed some
testing on my side. It seems by default the custom classes can be
transfered from webservice to .NET client proxy correctly. Have you done
any customization on the webservice or the client proxy? Also, as John
mentioned, do you create the webservice client proxy via "Add
WebReference"?

Here is the test webservice project code that I used. I used "Add
WebReference" to consume it in a client console application and it works
well.

=========================
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class CustomService : System.Web.Services.WebService {

public CustomService () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}


[WebMethod]
public MyCustomObj GetCustomObject()
{
MyCustomObj mco = new MyCustomObj();

mco.ObjID = "Object ID 1";
mco.ObjTitle = "Object Title 1";

List<ObjProperty> props = new List<ObjProperty>();

for (int i = 0; i < 5; ++i)
{
ObjProperty op = new ObjProperty();
op.PropertyName = "prop" + i.ToString();
op.PropertyType = "type_" + i.ToString();
op.PropertyValues = new StringCollection();
op.PropertyValues.Add("value1");

props.Add(op);


}

mco.ObjProperties = props;

return mco;
}

}


=========================


/// <summary>
/// Summary description for MyCustomObj
///
public class MyCustomObj
{
private string _ObjID;

public string ObjID
{
get { return _ObjID; }
set { _ObjID = value; }
}

private string _ObjTitle;

public string ObjTitle
{
get { return _ObjTitle; }
set { _ObjTitle = value; }
}
private List<ObjProperty> _ObjProperties;

public List<ObjProperty> ObjProperties
{
get { return _ObjProperties; }
set { _ObjProperties = value; }
}


}

public struct ObjProperty
{
public string PropertyName;
public string PropertyType;
public StringCollection PropertyValues;
}
========================================

If there is anything I missed, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: (E-Mail Removed).


--------------------
>From: "Rafia Tapia" <(E-Mail Removed)>
>Subject: webserve returning an object with List<T> not working
>Date: Mon, 3 Nov 2008 09:56:07 -0500


>Hi
>I have defined the following object that is return by my web service
>public class MyCustomObj
> {
> private string ObjID;
> private string ObjTitle;
> private List<ObjProperty> ObjProperties;
>
> //The above private variables have the corresponding public
>properties
> }
>public struct ObjProperty
> {
> public string PropertyName;
> public string PropertyType;
> public StringCollection PropertyValues;
>}
>when I invoke the web service through the browser, I see my object with

all
>of its properties including the type List<ObjProperty> but the object that
>is returned to the client application does not show the values of the
>variable defined in ObjProperty. In other words when I invoke the web
>service I get the following xml returned to the brower
>
><MyCustomObj>
> <ObjID>1</ObjID>
> <ObjTitle>Web Title</ObjTitle>
> <ObjProperties>
> <ObjProperty>
> <PropertyName>SEOEnabled</PropertyName>
> <PropertyType>System.Boolean</PropertyType>
> <PropertyValues>
> <string>False</string>
> </PropertyValues>
> </ObjProperty>
> <ObjProperty>
> <PropertyName>Users</PropertyName>
> <PropertyType>System.String</PropertyType>
> <PropertyValues>
> <string>Ben</string>
> <string>John</string>
> </PropertyValues>
> </ObjProperty>
> </ObjProperties>
></MyCustomObj>
>
>but the object return to the client application has count of two for the
>List<ObjProperties> variable but all the variables of each of the
>ObjProperty is null. Can anyone please tell me what I am doing wrong.
>
>Thanks
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mocked object returning another Mocked object Jean-Michel Pichavant Python 1 07-13-2012 10:37 AM
Working with C object of python object (pycairo,ctypes) AngelBlaZe Python 1 02-27-2007 09:37 AM
returning none when it should be returning a list? randomtalk@gmail.com Python 11 05-02-2006 10:26 AM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM



Advertisments