First we need to add the service reference
Give the Namespace as DataProvider
Now we'll go to the coding Here i have added the coding for the buttons Both button click events will have to be async.
private async void btnGetStudent_Click(object sender, RoutedEventArgs e) { //Create a client object to access the service DataProvider.DataProviderClient serviceClient = new DataProvider.DataProviderClient(); //Get the student id and convert it to integer int ID = Convert.ToInt32(txtStudentID.Text); //Get the student via the service DataProvider.Student student = await serviceClient.getStudentAsync(ID); //The service will return null if the student is not available //If student is not found show a message if (student==null) { Windows.UI.Popups.MessageDialog message = new Windows.UI.Popups.MessageDialog("Student not found"); message.ShowAsync(); return; } //Set the values to the appropriate labels lblFirstName.Text = student.FirstName; lblLastName.Text = student.LastName; } private async void btnGetAllStudents_Click(object sender, RoutedEventArgs e) { //Create a client object to access the service DataProvider.DataProviderClient serviceClient = new DataProvider.DataProviderClient(); //Get the student objects from the service ObservableCollection students = await serviceClient.getStudentsAsync(); //Add the objects to the list view foreach (DataProvider.Student student in students) { lstStudents.Items.Add(student.FirstName+" "+student.LastName); } }
No comments:
Post a Comment