Creating Search Queries Programmatically by using the Search Web Service in SharePoint Server 2007

Summary:  Learn how to programmatically create search queries by using the Search Web service in Microsoft Office SharePoint Server 2007.

Office Visual How To

Applies to:  Microsoft Office SharePoint Server 2007

Patrick Tisseghem, U2U

July 2007


Microsoft Office SharePoint Server 2007 includes a Web service named search.asmx that allows a remote client to execute a search query.

Code It

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.

Executing a Query

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.

Read It

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.

See It Creating Search Queries using Web Service video

Watch the Video

Length: 04:36 | Size: 2.63 MB | Type: WMV file

Explore It