How to: Submit a Keyword Query to SharePoint Foundation Search from a Client Application

[This documentation is preliminary and is subject to change.]

Search in Microsoft SharePoint Foundation 2010 includes the Query Web service, which exposes the search capabilities to client applications.

Note   In this context, "client application" refers to applications calling the Query Web service; this could include Microsoft ASP.NET Web applications, Windows Form applications, etc.

The QueryEx Web method of the Query Web service sends a query to the search service, and returns the results in a System.Data.DataSet.

Procedures

To submit a keyword query to SharePoint Foundation Search from a client application

  1. Create a proxy class for the Web service.

  2. If you are working in Visual Studio 2005, you can follow the steps outlined in How to: Create a Web Service Proxy Class for the SharePoint Foundation Search Web Service in Visual Studio.

    Alternatively you can use the Web Services Description Language Tool (Wsdl.exe), using the steps described in Creating an XML Web Service Proxy, then add a reference for the proxy class to the project for the client application

  3. Create a string variable and set it to the XML query string containing the keyword search query you want to pass to the search service.

  4. Create an instance of the Web service proxy class.

  5. If needed, specify the credentials to pass to the Web service.

  6. Call the QueryEx Web method of the Query Web service, storing the returned results in a System.Data.DataSet.

Code

//The string containing the keyword to use in the search
string keywordString = "Microsoft";
//The XML string containing the query request information 
//for the Web service
string qXMLString = "<QueryPacket xmlns='urn:Microsoft.Search.Query'>"+
"<Query><SupportedFormats><Format revision='1'>"+
"urn:Microsoft.Search.Response.Document:Document</Format>"+
"</SupportedFormats><Context><QueryText language='en-US' type='STRING'>"+
keywordString + "</QueryText></Context></Query></QueryPacket>";
QueryWebServiceProxy.QueryService queryService = new QueryWebServiceProxy.QueryService();
queryService.Credentials = System.Net.CredentialCache.DefaultCredentials;
System.Data.DataSet queryResults = queryService.QueryEx(qXMLString);
resultsGridView.DataSource = queryResults.Tables[0];

See Also

Tasks

How to: Create a Web Service Proxy Class for the SharePoint Foundation Search Web Service in Visual Studio

Concepts

SharePoint Foundation Query Web Service

Building SharePoint Foundation Search Queries

Reference

Keyword Syntax