Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"401 Not Authorized" error when authenticating a web service

Status
Not open for further replies.

afroblanca

Programmer
Jul 15, 2005
67
US
Here's the situation :

I have the same asp.net 2.0 web application running on both Machine A and Machine B. On both machines, I have Integrated Windows Authentication turned on, and Anonymous Access turned off. When I hit a certain page on Machine A, it will call the web service on Machine A, and then it will call the same web service on Machine B. Likewise, when I hit the same page on Machine B, it will call the web service on Machine B, and then it will call the same web service on Machine A.

On both machines, I have an account set up for this web service to use. The username/password for Machine A is different from the username/password for Machine B. The machines are on different Active Directory domains.

The websites on Machine A and Machine B use the same second-level domain, but have different subdomains.

On the page that calls the webservice, I have a block of code that looks like this :

try
{//call the webservice on Machine A
CacheMaintenance maintain = new CacheMaintenance("local.mysite.com");
maintain.Credentials = new NetworkCredential("LocalLoginName", "LocalPassword", "LocalDomain");
maintain.FlashTheCache();
maintain.Dispose();
}
catch (Exception exp)
{
errors = "Could not flash local cache. " + General.UnrollException(exp) + " ";
}

try
{//call the webservice on Machine B
CacheMaintenance maintain = new CacheMaintenance("testlive.mysite.com");
maintain.Credentials = new NetworkCredential("TestLiveLoginName", "TestLivePassword", "TestLiveDomain");
maintain.FlashTheCache();
maintain.Dispose();
}
catch (Exception exp)
{
errors += "Could not flash live cache. " + General.UnrollException(exp);
}

Machine A has no problem calling the webservice on Machine B. Likewise Machine B has no problem calling the webservice on Machine A. However, when Machine A tries to call the webservice on Machine A, or when Machine B tries to call the webservice on Machine B, I get a "401 Not Authorized" error.

Does anybody know why I'm getting this error?

Thanks for your help.
 
Here's a minor correction to my original post :

Originally, I said that Machine A could call the webservice on Machine B but not on Machine A, and that Machine B could call the webservice on Machine A but not on
Machine B. After some more testing, I realized this was not the case.

Machine A is a Windows 2000 Server machine. It is capable of calling the webservice on Machine A and on Machine B.

Machine B is a Windows 2003 Server machine. It is capable of calling the webservice on Machine A, but not Machine B.

Here are some things I tried :

I tried having Machine B call the webservice on Machine B using CredentialCache.DefaultCredentials.
I tried having Machine B call the webservice on Machine B using CredentialCache.DefaultNetworkCredentials.
I tried having Machine B call the webservice on Machine B using the administrator account credentials.
I tried having Machine B call the webservice on Machine B without setting the credentials at all.

All to no avail. This seems strange to me. Why would Machine A be able to call the webservice on Machine B, but Machine B couldn't call the webservice on Machine B with the very same credentials?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top