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.

2 Answers 2


Try using CredentialCache.DefaultNetworkCredentials instead of creating the credentials.

  • Thanks for the suggestion, but it doesn't help in this case.
    – Dan
    Commented Nov 16, 2010 at 10:28

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.

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.