title: Sharepoint 2010 search via webservice gives "Attempted to perform an unauthorized operation"
body: <p>We've set up Sharepoint search (not enterprise though) to index some of our standard asp.net sites and if I go to the search page in sharepoint and search for anything specific I get the results back that I am looking for.  </p>
  
  <p>However I am trying to consume the search webservice from a standard website (not in sharepoint) now and getting a "Attempted to perform an unauthorized operation" error.  I know I am authenticating properly, since fiddler shows me the 401 and then the 200 response to say that it is OK. However the moment I call .Query (the last line in my code sample) it gives me the error.</p>
  
  <p>This is my code</p>
  
  <pre><code>searchcentre2.QueryService queryService = new searchcentre2.QueryService();
  System.Net.NetworkCredential _credentials = new System.Net.NetworkCredential(_username, _password, _domain);
  queryService.Credentials = _credentials;
  queryService.UseDefaultCredentials = false;
  queryService.PreAuthenticate = true;
  queryService.Url = _url;
  m_lSearchResutls.Text = queryService.Query(queryxml.ToString());
  </code></pre>
  
  <p>I have tried and currently running all three of the following.</p>
  
  <ol>
  <li>Turning anonymous off everywhere, both my local site and the sharepoint search section.</li>
  <li>Setting the credentials with my own, and I am in the site owners and site collection administrators group</li>
  <li>Gave my machine name access to the site collection administrators group (as per my sysadmin's advice as the both sites application pool runs under the network service account)</li>
  </ol>
  
  <p>Is there anything else that I need to set or fix or look at? I am running out of ideas of things to try.  Is it something on the sharepoint side that I have to set up still?  </p>
  
  <p>I have tried both search.asmx/spsearch.asmx and .Query/.QueryEx and there was no difference in the error message above.</p>
  
  <p>There are code samples out there where you use basic authentication by adding it to the header which I have tried but that didnt work either.  I've even tried NTLM, however if it was my security I wouldnt have gotton a 401 and then 200 response surely?</p>
  
  <p>So now I am beginning to think that it is something on Sharepoint side that I have to change.  But what?</p>
  
  <p>Any help would be appreciated.</p>