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("<Query>");
sb.Append("<Context>");
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("</QueryText>");
sb.Append("</Context>");
sb.Append("<Range><Count>" + resultcount.ToString() + "</Count></Range>");
sb.Append("</Query>");
sb.Append("</QueryPacket>");
but I get this error msg:
<ResponsePacket xmlns="urn:Microsoft.Search.Response">
<Response domain="">
<Status>ERROR_SERVER</Status>
<DebugErrorMessage>System.Collections.Generic.KeyNotFoundException</DebugErrorMessage>
</Response>
</ResponsePacket>
(reposted from http://stackoverflow.com/q/6580020/67249)
---UPDATE
I found a lab exercise to do this exact search at http://msdn.microsoft.com/en-us/gg981317, 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 http://www.codeproject.com/KB/sharepoint/DepartmentPeopleViewer1.aspx?display=Print and STILL I got the System.Collections.Generic.KeyNotFoundException message!
Searching for normal documents bring back results though.
---UPDATE 3
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.
---UPDATE 4
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!
'char ? if yes, this may create a wrong query... you should escape this arguments – Steve B Jul 5 '11 at 13:56