webserve returning an object with List<T> not working

Discussion in 'ASP .Net Web Services' started by Rafia Tapia, Nov 3, 2008.

  1. Rafia Tapia

    Rafia Tapia Guest

    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
     
    Rafia Tapia, Nov 3, 2008
    #1
    1. Advertising

  2. "Rafia Tapia" <> wrote in message
    news:...
    > 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
     
    John Saunders, Nov 3, 2008
    #2
    1. Advertising

  3. Rafia Tapia

    Steven Cheng Guest

    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: .

    ==================================================
    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.


    --------------------
    >From: "Rafia Tapia" <>
    >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
    >
    >
    >
     
    Steven Cheng, Nov 4, 2008
    #3
  4. Rafia Tapia

    Steven Cheng Guest

    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: .


    --------------------
    >From: "Rafia Tapia" <>
    >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
    >
    >
    >
     
    Steven Cheng, Nov 4, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel
    Replies:
    0
    Views:
    430
    darrel
    Apr 27, 2004
  2. =?Utf-8?B?QW5nZWw=?=

    Drop Down List not returning selectedIndex

    =?Utf-8?B?QW5nZWw=?=, Apr 7, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    968
    Craig Deelsnyder
    Apr 7, 2005
  3. Replies:
    11
    Views:
    671
    Christos Georgiou
    May 2, 2006
  4. Shane Geiger
    Replies:
    4
    Views:
    391
    bullockbefriending bard
    Mar 25, 2007
  5. Jean-Michel Pichavant

    Mocked object returning another Mocked object

    Jean-Michel Pichavant, Jul 13, 2012, in forum: Python
    Replies:
    1
    Views:
    206
    Ulrich Eckhardt
    Jul 13, 2012
Loading...

Share This Page