0

Below is my Applied code for Search in ISAPI WCF service, here when I debug DataTable count gives me zero. It works fine in SharePoint 2010 OOTB Search and have also configured Crawl settings. Can you please help me out guys.

try
        {                
            SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site));

            KeywordQuery keywordQuery = new KeywordQuery(proxy);
            keywordQuery.ResultsProvider = SearchProvider.Default;
            keywordQuery.ResultTypes = ResultType.RelevantResults;
            keywordQuery.TrimDuplicates = true;
            keywordQuery.RowLimit = 10;
            keywordQuery.QueryText = queryText;
            keywordQuery.SortList.Add("LastModifiedTime", Microsoft.Office.Server.Search.Query.SortDirection.Descending);
            keywordQuery.HiddenConstraints = string.Concat("scope:\"", "All Sites", "\"");

            ResultTableCollection results = keywordQuery.Execute();
            ResultTable result = results[ResultType.RelevantResults];
            DataTable dt = new DataTable();
            dt.Load(result, LoadOption.OverwriteChanges);

            DataTable dtFinal = dt.Copy();
        }
        catch (Exception ex)
        {
        }

Here is the image of DataTable count

enter image description here

1 Answer 1

0

After some more research I have found out the solution.

You need to write SPSecurity.RunWithElevatedPrivileges(delegate(), as no user would be found while accessing SharePoint site in this ISAPI wcf service, so RunWithEvelatedPrivileges would help to perform access.

     try
        {
            string siteurl = SPContext.Current.Web.Url;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(siteurl))
                {
                    KeywordQuery keywordQuery = new KeywordQuery(site);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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