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
- Using Visual Studio, open the starter solution from <Install> \Labs\APUQWS\Source\Begin\ SillverlightQueryPeopleWebService.sln.
- Right-click the References folder in the Silverlight.QueryWebService project.
- Select Add Service Reference to display the Add Service Reference dialog.
- Enter https://intranet.contoso.com/_vti_bin/search.asmx into the address textbox
- Click Go to locate the service.
- Enter QueryWebService in the Namespace textbox.
- Click Ok
Task 2 – Completing the PeopleViewModel Class.
- Right-click on the PeopleViewModel.cs file and select Open.
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
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
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
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
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
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
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
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.
- Right-click MainPage.xaml and select Open.
Review the MainPage.xaml markup.
- Right-click MainPage.xaml and select View Code.
Add a variable named ViewModel of type PeopleViewModel.
Figure 12
View Model Variable
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
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.
- Right-click on the SharePoint.Client.QueryPeopleWebSearch project in Solution Explorer and select Set as StartUp Project.
- Press F5 to build and deploy.
- After Internet Explorer, launches navigate to https://intranet.contoso.com/ PeopleSearchDemo.aspx.
- 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.
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