Condividi tramite


Windows SharePoint Services Query Web Service

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Search in Windows SharePoint Services exposes its search functionalities through a Web service. This allows you to access Search results from client applications and Web applications outside of the context of a SharePoint site.

Accessing the Query Web Service

To access the SearchQuery Web service and its methods, set a Web reference to the following:

http://<Site_Name>/_vti_bin/spsearch.asmx

Note   For step-by-step instructions for setting a Web reference with Microsoft Visual Studio 2005, see How to: Create a Web Service Proxy Class for the Windows SharePoint Services Search Web Service in Visual Studio.

Web Methods

The following table describes the Web methods available in the Query Web service.

Name

Description

Query

Returns a set of results in an XML string for the specified query.

QueryEx

Returns a set of results in a Microsoft ADO.NET DataSet object for the specified query.

Registration

Returns the name for a specified site.

Status

Returns availability of the search service.

Query Methods

The Query Web service includes two methods for retrieving Search results: Query and QueryEx.

Both methods accept the same input, a string containing XML that specifies the search query parameters; however, the format of the returned results differs. The QueryEx method returns the search results in a System.Data.DataSet object, and the Query method returns the search results in a string as XML. For more information, see the 'Returning the Search Results' section later in this topic.

Building the XML for the Search Query

The XML format for the search query is defined in the Microsoft.Search.Query Schema.

The actual search query is specified in the QueryText element. You can build the search query by using either the SQL or Keyword syntax; you specify the syntax that is used in the QueryText element's type attribute.

The following code example is sample XML for the QueryText element that specifies a search query using SQL syntax.

<QueryText language=en-us type='MSSQLFT'>
SELECT Title, Path, Description, Write, Rank, Size FROM Scope() WHERE FREETEXT(DEFAULTPROPERTIES,'SharePoint') ORDER BY Rank
</QueryText>

Note

If you are using SQL syntax with the Query method, you must specify the following properties in the SELECT statement of the SQL query: Title, Path, Description, Write, Rank, and Size.

The following code example is sample XML for the QueryText element that specifies a search query using Keyword syntax.

<QueryText language=en-us type='STRING'>
SharePoint
</QueryText>

Returning the Search Results

The QueryEx method returns the search results in a System.Data.DataSet object. The DataSet object contains a System.DataSet.DataTable object for each result type that is returned.

The Query method returns the search results in a string as XML. The format for the XML is defined by the Microsoft.Search.Response and Microsoft.Search.Response.Document schemas. The full set of search results is contained in the Results element of the Microsoft.Search.Response schema, with each individual result represented by a Document element of the Microsoft.Search.Response.Document schema.

In This Section

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

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

Reference

QueryService

Microsoft.Search Schemas for Windows SharePoint Services Search Query Service

Building Windows SharePoint Services Search Queries