System.ServiceModel.FaultException Error When Using QueryService.QueryEx

The QueryService.QueryEx method is pretty useful in custom applications that leverage the inbuilt query features of SharePoint since it provides a System.Data.DataSet object containing a System.Data.DataTable object for each search result set, so can contain multiple result sets. Usually people use it to build custom views of mined data ala the search features, its utility is noticeable in it’s ease.

After migrating a pre-production SharePoint 2007 instance to 2010, my current client pointed out that one of their custom WebParts that make use of the QueryEx method was not functioning and bubbling up a System.ServiceModel.FaultException.

Looking at the ULS logs, I saw the following error being thrown:

Exception caught in QueryService class. Exception message: Exception from HRESULT: 0x80040E01. Stack: Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at

Microsoft.Office.Server.Search.Query.QueryService.DoQuery(QueryMethod queryMethod, String queryXml, String& domain, String& queryId, Int32& startAt, Boolean& fStandardResults, StringCollection& querySuggestions) at Microsoft.Office.Server.Search.Query.QueryService.QueryEx(String queryXml).

If you get this error (it should be noted that you can get a similar error when working with the FullTextSqlQueryclass as well, you must reduce the RowLimit in the query. It should be noted that the RowLimit ceiling is 917728059 and you should not use MaxValue.