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" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Adress}" FontSize="25"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>