none
Sharepoint QueryService (search.asmx) access and authentication issue

    Question

  • I am attempting to use the Sharepoint QueryService (_vti_bin/search.asmx) installed on server hosted in our organization.  I have created the service proxy in my Visual Studio 2005 solution and wrote the C# code to communicate with the QueryService.  When I make a simple call, I receive the error "Attempted to perform an unauthorized operation".  I have verified that the IIS virtual directory settings on the Sharepoint service app is set as Anonymous Authentication = Disabled and Windows Authentication = Enabled.  My proxy call code looks like this:

    SearchService.QueryService _service = new ConsoleApplication1.SearchService.QueryService();
    _service.UseDefaultCredentials = true;
     
    string _xml = _service.Status();

    Help is greatly appreciated.  Thank you.

     


    Scott Bland
    Friday, October 14, 2011 5:52 PM

Answers

  • The problem turned out to be very basic.  Permissions were not granted to "authenticated user" in any of the Sharepoint permission groups.  Once I added "authenticated user" to the Viewers group, everything worked perfectly.
    Scott Bland
    • Marked as answer by Wayne Fan Tuesday, October 25, 2011 1:31 AM
    Monday, October 24, 2011 4:25 PM

All replies

  • Hi Scott,

     

    Thanks for your post.

    When you call the web service, you should set the Credentials property in your code.

    // Create a QueryService object.

    QueryService.QueryService queryService = new QueryService.QueryService();

     

    // Set authentication credentials.

    NetworkCredential networkCredential =

    CredentialCache.DefaultCredentials.GetCredential(new

    Uri(queryService.Url), "NTLM");

    queryService.Credentials = networkCredential;

     

    if you will call the web service in another SharePoint, you have to set the “URL” property for the web service.

     

    http://msdn.microsoft.com/en-us/library/bb852171.aspx

    http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/07/17/how-to-query-search-using-the-web-service.aspx

    Monday, October 17, 2011 2:06 AM
  • Thanks.  I gave it a try, but same error.   I am pretty sure it's a Sharepoint installation/configuration issue, because my code works when I point to a different installation of Sharepoint 2010 running on a different server.
    Scott Bland
    Monday, October 17, 2011 4:42 PM
  • The problem turned out to be very basic.  Permissions were not granted to "authenticated user" in any of the Sharepoint permission groups.  Once I added "authenticated user" to the Viewers group, everything worked perfectly.
    Scott Bland
    • Marked as answer by Wayne Fan Tuesday, October 25, 2011 1:31 AM
    Monday, October 24, 2011 4:25 PM
  • My fix is to add the user to the viewers group.
    Wednesday, October 10, 2012 6:15 PM