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