locked
Accessing child object properties of a wcf responce RRS feed

  • Question

  • User10286831 posted
    I've developped a wcf service and using it from javascript but a cannot access properties of sub objects. A can access the createdOn value but not the center or country one Here's bellow some code or tracing information: JS: jQuery.ajax({ type: 'POST', contentType: 'application/json; charset=utf-8', url: '../services/1/integrated/studydataservice.svc/Execute', data: JSON.stringify({ request: WhoAmIRequest }), async: true, success: function (data, textStatus) { var response; response = data.hasOwnProperty("d") ? data.d : data; alert(response.UserInfo.Country.Name); ... C#: [Serializable] [DataContract(Namespace="Solution1.eCrfKernel")] public class SystemUserInfo { [DataMember] public Reference Center { get; set; } [DataMember] public Reference Country { get; set; } [DataMember] public DateTime CreatedOn { get; set; } ... Trace: <root type="object" xmlns=""> <d type="object" __type="WhoAmIResponse:Solution1.eCrfKernel"> <UserInfo type="object" __type="SystemUserInfo:Solution1.eCrfKernel"> <Center type="object" __type="Reference:#Solution1.eCrfKernel"> <a:item xmlns:a="item" item="<Id>k__BackingField" type="number">4</a:item> <a:item xmlns:a="item" item="<Name>k__BackingField" type="string">center 1</a:item> </Center> <Country type="object" __type="Reference:#LambdaPlus.eCrfKernel"> <a:item xmlns:a="item" item="<Id>k__BackingField" type="number">21</a:item> <a:item xmlns:a="item" item="<Name>k__BackingField" type="string">Belgium</a:item> </Country> <CreatedOn type="string">/Date(1353078558897+0100)/</CreatedOn> ..... Any idea why the js code returns undefined when i try to access the name of the country? Thanks Mathieu
    Saturday, March 16, 2013 3:14 AM

Answers

  • User-1658256289 posted

    Please reformat the code snipets for easier reading.

    mbr

    A can access the createdOn value but not the center or country one

    How do you define the class etc.

    Check the replies in this duplicated thread. 

    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/352ccead-3c44-4182-b21a-bfc6369c8038

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 17, 2013 10:13 PM