Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All

I developed the wcf rest service and i consumed in windows phone7.1
but my listbox was empty.
XML
public List<Product> GetProducts()
        {
            PractiseEntities db = new PractiseEntities();
            var students = from p in db.StudentEntities select p;
            List<Product> st1 = students.ToList().ConvertAll(new Converter<StudentEntity, Product>(TranslateStudentEntityToStudent1));

            return st1;

C#
private Product TranslateStudentEntityToStudent1(StudentEntity student)
        {
            Product p = new Product();
            p.ProductID = student.ID;
            p.ProductName = student.Name;
            p.QuantityPerUnit = student.Adress;
            p.UnitPrice = student.DOB;
            return p;

        }


Windows Phone7.1 app:
XML
private void btn_getdata_Click(object sender, RoutedEventArgs e)
        {
            WebClient proxy1 = new WebClient();
            proxy1.DownloadStringCompleted += new DownloadStringCompletedEventHandler(proxy1_DownloadStringCompleted);
            proxy1.DownloadStringAsync(new Uri("http://localhost:49166/RestService.svc/Student"));
 }
  private void proxy1_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
Stream s = new MemoryStream(Encoding.Unicode.GetBytes(e.Result));
            DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(List<Student>));
            List<Student> result = obj.ReadObject(s) as List<Student>;
            listBox2.ItemsSource = result;
        }

XML
ListBox Height="172" Foreground="White" FontSize="25" HorizontalAlignment="Left" Margin="20,31,0,0" Name="listBox2" VerticalAlignment="Top" Width="401" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
  <TextBlock Text="{Binding Adress}" FontSize="25"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
Posted
Updated 20-Mar-13 22:22pm
v3

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