0

I am having a strange problem in accessing the SharePoint 2013 search object model. I have a custom class, when the code is excuted in console application, it's works ok. but in wcf, the return result always 0 result.

here is the main code:

    private int SearchTest(string siteUrl, string queryText, int rowLimit, int startRow, string loginUserName)
    {
        //get current user token
        SPUserToken curUserToken = GetUserTokenByUser(siteUrl, loginUserName);

        //using (SPSite site = new SPSite(siteUrl, curUserToken))
        using (SPSite site = new SPSite(siteUrl))
        {
            KeywordQuery keywordQuery = new KeywordQuery(site);

            keywordQuery.ResultsProvider = SearchProvider.Default;
            keywordQuery.QueryText = queryText;
            keywordQuery.RowLimit = rowLimit;
            keywordQuery.StartRow = startRow;

            SearchExecutor searchExecutor = new SearchExecutor();
            ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);

            var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);

            var resultTable = resultTables.FirstOrDefault();
            //output result 
            return resultTable.TotalRows;
        }
    }

Any idea why is this happening?

the wcf service hosted in SharePoint, and call the wcf code as below:

SPSLamsServiceClient client = new SPSLamsServiceClient();

client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("userName", "password", "domain"); 

var search = client.Search(siteUrl, "test", 20, 0, "userloginname");
0

Sounds like you are losing your impersonation context. Is the wcf service hosted in SharePoint?

  • yes, the wcf service hosted in SharePoint, and call the wcf code as below: SPSServiceClient client = new SPSServiceClient(); client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("userName", "password", "domain"); – chia_liu May 23 '13 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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