Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
General Reference
Query Web Service
 How to: Submit a Keyword Query to W...

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
How to: Submit a Keyword Query to Windows SharePoint Services Search from a Client Application

Search in Windows SharePoint Services 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 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 Windows SharePoint Services 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 Windows SharePoint Services 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

C#
//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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker