Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WCF
Hi All
 
I developed the wcf rest service and i consumed in windows phone7.1
but my listbox was empty.
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;
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:
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;
        }
ListBox Height="172" Foreground="White" FontSize="25" HorizontalAlignment="Left" Margin="20,31,0,0" Name="listBox2" VerticalAlignment="Top" Width="401" >
Posted 20-Mar-13 23:05pm
Edited 20-Mar-13 23:22pm
v3

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

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 105
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 21 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100