SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom IRM module and a custom webservice, both installed into Sharepoint. The module attempts to call the service with the following code:

MyService lService = new MyService();
lService.Credentials = new System.Net.NetworkCredential(SERVICE_CRED_USER, SERVICE_CRED_PASS, SERVICE_CRED_DOMAIN);
bool lResult = lService.TestMethod();

In my development environment this works fine, in the live environment (with a much more complicated SharePoint setup) I get:

Critical Error: The request failed with HTTP status 401: Unauthorized.-
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)

In both cases the credentials being used are those of a user on the local machine. The credentials in question can log in to the SharePoint site.

So can anyone shed any light on what might be going wrong?

I've spent a good few hours trawling Google for Sharepoint and 401 but so far no joy (this doesn't appear to fit the symptoms for a loopback error as there are no Failure Audits in the security log).

Edit: I tried temporarily disabling the loopback check and it didn't help. I've also found out that the live environment is only on SP1 where as the environment is on SP2, not sure that that should matter though.

share|improve this question

Try using CredentialCache.DefaultNetworkCredentials instead of creating the credentials.

share|improve this answer
Thanks for the suggestion, but it doesn't help in this case. – Dan Nov 16 '10 at 10:28
up vote 0 down vote accepted

I've managed to add some logging to the web service and prove that it is being called. So in this case the 401 error must be coming from something the WebService is trying to do, rather than from the attempt to call the WebService.

Hopefully this will help someone else avoid quite so much hair pulling.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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