Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to populate longlist via WCF service. There are no errors in the code, just the result of the executed program looks like: "PhoneApp1.ServiceReference1.worker" instead of the name and other data I want to display. My service implementation is:
C#
public IEnumerable<worker> GetStuffList()
        {
            List<worker> stuffList = new List<worker>();
            stuffList.Add(new worker("John", 23, true));
            stuffList.Add(new worker("Nick", 22, true));
            stuffList.Add(new worker("Gill", 23, false)); 
            return stuffList;
        }

        private List<Group<worker>> GetStuffEnumerable()
        {
            IEnumerable<worker> stuffList = GetStuffList();
            return GetItemGroups(stuffList, c => c.Age.ToString());
        }

        private static List<Group<T>> GetItemGroups<T>(IEnumerable<T> itemList, Func<T, string> getKeyFunc)
        {
            IEnumerable<Group<T>> groupList = from item in itemList
                                              group item by getKeyFunc(item) into g
                                              orderby g.Key
                                              select new Group<T>(g.Key, g);

            return groupList.ToList();
        }

        public class Group<T> : List<T>
        {
            public Group(string name, IEnumerable<T> items)
                : base(items)
            {
                this.Title = name;
            }

            public string Title
            {
                get;
                set;
            }
        }

My service interface is:
C#
[ServiceContract]
    public interface IService1
    {
        [OperationContract]
       IEnumerable<worker> GetStuffList();
     
    }

   [DataContract]
    public class worker
    {
        public string Name;
        public int Age;
        public bool Sex;

        public worker(string Name, int Age, bool Sex)
        {
            this.Age = Age;

            this.Name = Name;
            this.Sex = Sex;
        }
    }

My WP page code is:
C#
private void Button_Click(object sender, RoutedEventArgs e)
       {
           ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
           proxy.GetStuffListCompleted += showList;
           proxy.GetStuffListAsync();
       }
       private void showList(object sender, ServiceReference1.GetStuffListCompletedEventArgs e)
       {
           this.longlist.ItemsSource = e.Result;
       }

I think it has to be something with "this.longlist.ItemsSource = e.Result", but don't know how to correct it.
Posted
Updated 17-Jun-14 5:40am
v2

1 solution

Apply the DataMemberAttribute to fields (or properties) that must be serialized.
C#
[DataContract]
public class worker
{
    [DataMember]
    public string Name;
    [DataMember]
    public int Age;
    [DataMember]
    public bool Sex;

    public worker(string Name, int Age, bool Sex)
    {
        this.Age = Age;

        this.Name = Name;
        this.Sex = Sex;
    }
}
 
Share this answer
 
Comments
Purple Cucumber 17-Jun-14 12:13pm    
I did it and still have the same problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900