webserve returning an object with List<T> not working

R

Rafia Tapia

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
 
J

John Saunders

Rafia Tapia said:
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.
 
S

Steven Cheng

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/archive/2007/06/20/vs-2008-multi-targeting-su
pport.aspx

http://blogs.msdn.com/dajung/archive/2008/03/17/vs2008-and-multi-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/2008/01/02/how-is-the-net-framework-3-5-d
ifferent-from-net-2-0-and-net-3-0.aspx

http://blogs.msdn.com/johnmullinax/archive/2008/01/09/what-is-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: (e-mail address removed).

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

http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

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


--------------------
 
S

Steven Cheng

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 address removed).


--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top