SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to access search for people in SharePoint 2010 from a webservice.

I have tried this querypacket:

            sb.Append("<QueryPacket xmlns='urn:Microsoft.Search.Query'>");
            sb.Append("<QueryText language=\"en-US\" type=\"MSSQLFT\">");
            sb.Append("SELECT ");
            sb.Append("preferredname, ");
            sb.Append("Department, ");
            sb.Append("WorkPhone, ");
            sb.Append("WorkEmail, ");
            sb.Append("Path ");
            sb.Append("FROM SCOPE() ");
            sb.Append("WHERE ");
            sb.Append("(\"DAV:contentclass\" = 'urn:content-class:SPSPeople') ");
            sb.Append(" AND (\"FirstName\" LIKE '" + fname + "%') AND (\"LastName\" LIKE '" + lname + "%')");             
            sb.Append("<Range><Count>" + resultcount.ToString() + "</Count></Range>");

but I get this error msg:

<ResponsePacket xmlns="urn:Microsoft.Search.Response">
   <Response domain="">

(reposted from


I found a lab exercise to do this exact search at, And when I copied the query, I still got the KeyNotFoundException exception. My query is not at fault. I am searching against the 2010 Information Worker Demonstration and Evaluation Virtual Machine as per the Lab

---UPDATE 2 Copied the query from and STILL I got the System.Collections.Generic.KeyNotFoundException message!

Searching for normal documents bring back results though.


Using the tool suggested by Chris Beckett (thank you!) I run this query: SELECT * FROM SCOPE() WHERE "scope"= 'People' and get the same error as above.


I finally got results: the issue was not the queries, but the fact that the IW VM was using our company's DNS! Fixed that, and every people search works! Thank you for all the contributions!

share|improve this question
does your "fname" or "lname" contains ' char ? if yes, this may create a wrong query... you should escape this arguments – Steve B Jul 5 '11 at 13:56
+1 for detailed error messages and steps to reproduce – Tom Resing Jul 7 '11 at 16:20
up vote 5 down vote accepted

The Search Query syntax is finicky and a lot of people have problems getting it just right. There is a fantastic tool you can use to test and customize your search query until you get it right: [<= URL seems to be invalid, looking for update. RK]

Download the search test tool, fill out the input fields, and it generates the Query Xml, and can even execute and return the results in Xml or Dataset format.

My next suggestion is to incrementally cut down the query until it executes (e.g. remove the And from the Where clause, remove fields from the Select clause) to try to isolate which part may be causing the problem.

UPDATE: I wish you had mentioned that you had FAST installed. Although the syntax is mostly the same for calling the search web service, when fast is installed you now have the option of submitting queries targeted at SharePoint Search using Keywords or SQL syntax, or FAST using FQL. This makes the syntax of the query that needs to be submitted a little different.

I cleaned up a copy of the request Xml to support a SharePoint server with FAST integration - you can download the sample here:

share|improve this answer
I did try this tool, and somehow the Query still gives me the KeyNotFoundException while QueryEx returns a dataset when querytype is set to SQL (using the tool) – callisto Jul 7 '11 at 11:50
+1 for multiple troubleshooting steps the original poster values. Going the extra mile would be testing this on the IW VM. – Tom Resing Jul 7 '11 at 16:21
Try the following - this query worked for me using the moss-search tool: "Select path from scope() where contentclass = 'urn:content-class:SPSPeople' – Chris Beckett Jul 7 '11 at 20:07
@Chris Beckett: I get 0 results when running your query on the Information Worker VM, which has a sps3 Content Source with 284 successful hits after a crawl. (using the mosssearch tool) – callisto Jul 14 '11 at 9:50
Chris, the link you give at the top is apparently no longer valid. I am going to remove the a tag until it can be updated. – Robert Kaucher Feb 20 '14 at 17:37

'Select * ' will not work, please try:

FROM Scope()
WHERE "SCOPE" = 'People'

It looks like one (or more) of the fields you're using in the query don't exist.

share|improve this answer
Boerbbom: I get 0 results when running your query on the Information Worker VM, which has a sps3 Content Source with 284 successful hits after a crawl.(using the mosssearch tool) – callisto Jul 14 '11 at 9:54
And with SearchCoder? – Anita Boerboom Jul 14 '11 at 10:42
It connects fine, but when I Build/Execute SQL I get: "The given key was not present in the dictionary". Running the query as Web Service (Radio buttun on [RUN] tab) causes unhandled exception "Cannot find table 0" – callisto Jul 14 '11 at 10:50
You were running the above query I suggested? – Anita Boerboom Jul 14 '11 at 12:09
yes, I was using your query. – callisto Jul 14 '11 at 19:53

Stupid remark maybe, but:

  • Does search for userprofiles work in your UI? you can check it out by entering "content-class:SPSPeople" in your searchbox.
share|improve this answer
I did not get any results for your suggestion: "We did not find any results for content-class:SPSPeople." – callisto Jul 11 '11 at 11:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.