Microsoft Office SharePoint Server 2007 includes a Web service named search.asmx that allows a remote client to execute a search query.
Developers working in Microsoft Visual Studio 2005 add a Web reference to the project that points to the search.asmx Web service, located in the _vti_bin directory off the top-level (root) of the SharePoint site. After the proxy class is created, you can start programming. Two Web methods that are exposed by the Web service—Query and QueryEx—are addressed in this Office Visual How-To.
Request Query Packet
The call to either the Query or QueryEx Web method is simple. One parameter is a blob of XML containing all of the information required for the search service to execute the query. The request query packet used for a keyword query follows.
You execute the query by first creating an instance of the proxy class. Next, you have to perform the authentication. You can pass the credentials of the currently logged-on user (as shown in the code example), or you can create an instance of the NetworkCredential class. For the latter option, you must pass the credential information to the constructor. The request query packet containing the keyword query is passed simply as the only parameter with both the Query and QueryEx methods. The Query method returns the search results in raw XML format. The QueryEx method returns the search results as a serialized DataSet object. The proxy class makes the DataSet object directly available so that you can bind it to one of your user interface (UI) controls.
Dim searchService = New SearchServiceLab.SearchService.QueryService()
searchService.Credentials = _
System.Net.CredentialCache.DefaultCredentials
Dim queryString asString = keywordQueryTemplate.Replace _
("query_text_placeholder", KeywordTextBox.Text.Trim())
Dim queryResults AsString = searchService.Query(queryString)
MessageBox.Show(queryResults)
Dim resultDataset As DataSet = searchService.QueryEx(queryString)
ResultDataGridView.DataSource = resultDataset.Tables(0)
The Search Web Service exposed by Microsoft Office SharePoint Server 2007 allows for remote execution of a search query. The query must be encapsulated in a request packet and can either be formulated with the keyword syntax or the full-text SQL syntax.
Two methods allow for the execution of the query:
Query: Accepts a request packet and returns a response packet that includes the search results in XML format.
QueryEx: Accepts a request packet and returns a response packet that includes the search results formatted as a DataSet object serialized as XML.