Exercise 2: Complete a Silverlight Application using FullText Query and Execute an Asynchronous Web Service Call

In this exercise, you will create a FullText Query using Search.asmx web service and execute it asynchronously.

Task 1 – Adding a Service Reference to Search.asmx

  1. Using Visual Studio, open the starter solution from <Install> \Labs\APUQWS\Source\Begin\ SillverlightQueryPeopleWebService.sln.
  2. Right-click the References folder in the Silverlight.QueryWebService project.
  3. Select Add Service Reference to display the Add Service Reference dialog.
  4. Enter https://intranet.contoso.com/_vti_bin/search.asmx into the address textbox
  5. Click Go to locate the service.
  6. Enter QueryWebService in the Namespace textbox.
  7. Click Ok

Task 2 – Completing the PeopleViewModel Class.

  1. Right-click on the PeopleViewModel.cs file and select Open.
  2. Create a collection to hold the search results for people. The People collection will contain Person objects. Use snippet 4.2.1 to add the collection to the PeopleViewModel class.

    Figure 3

    People Collection

  3. Create a CurrentPerson property using snippet 4.2.2. This property will contain a reference to the currently selected person and will be bound to by the user interface.

    Figure 4

    Property Current Person

  4. Add initialization code in the constructor to initialize the People collection. Use snippet 4.2.3 to include the initialization code.

    Figure 5

    People View Model

  5. Use snippet 4.2.4 to add the body to the GenerateSearchQuery method. This method does not actually perform the query but simply creates the query Xml that is sent to the Query Web Service. This lab is using Full Text Search Syntax and limits the search to the only those results with a content class of SPSPeople. The method accepts a searchCriteria parameter that is matched using a LIKE clause and a % wild card value.

    Figure 6

    Generate Search Query Method

  6. Use snippet 4.2.5 to complete the GetSearchServiceProxy method. This method is a helper method that retrieves the host value from Silverlight and configures the correct endpoint proxy.

    Figure 7

    Search Service Proxy

  7. Use snippet 4.2.6 to complete the GetPeople method. This method defines the QueryCompleted event handler and starts the asynchronous query using the query Xml passed in the searchCriteria parameter.

    Figure 8

    Get People method

  8. The GetPeople_QueryCompleted handler passes the results to the ProcessPeopleSearchResults method. Use snippet 4.2.7 to add the call to ProcessPeopleSearchResults.

    Figure 9

    Get People Query Completed Method

  9. Use snippet 4.2.8 to complete the ProcessPeopleSearchResults method. This method parses the Xml results and creates a single Person object for each result. The Person object is added to the People collection. The user interface is bound to the People collection.

    Figure 10

    Process People Search Results Method

Task 2 – Completing the MainPage Class.

  1. Right-click MainPage.xaml and select Open.
  2. Review the MainPage.xaml markup.

    Figure 11

    MainPage.xaml

  3. Right-click MainPage.xaml and select View Code.
  4. Add a variable named ViewModel of type PeopleViewModel.

    Figure 12

    View Model Variable

  5. Add code to the constructor to initialize the viewModel variable and set the application’s DataContext to the viewModel variable.

    Figure 13

    Main Page Method

  6. Use snippet 4.2.9 to complete the btnSearch_Click method.

    Figure 14

    Search Click Button method

Task 3 – Deploying and Testing the Silverlight Application.

  1. Right-click on the SharePoint.Client.QueryPeopleWebSearch project in Solution Explorer and select Set as StartUp Project.
  2. Press F5 to build and deploy.
  3. After Internet Explorer, launches navigate to https://intranet.contoso.com/ PeopleSearchDemo.aspx.
  4. Enter the letter c into the text box and click the Search button. Silverlight application will display a list of users starting with the letter c.
  5. Click on Cheley, Erika. Erika’s information is displayed in the top right side of the application. Erika’s document now display in the Recent Documents pane.

    Figure 15

    People Search Demo