Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
[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.
Create a proxy class for the Web service.
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
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.
Create an instance of the Web service proxy class.
If needed, specify the credentials to pass to the Web service.
Call the QueryEx Web method of the Query Web service, storing the returned results in a System.Data.DataSet.
//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];
SharePoint Foundation Query Web Service