I'm calling a web service (named SecurityService) as below:
SecurityService.Service securityService = new SecurityService.Service();
securityService.Credentials = networkCredential;
return securityService.GetUserToken();
The service has Windows Authentication enabled, nothing else. This piece of code above works, from remote machines.
When I push this same code out to the IIS server that this service is running on, I get a 401 error:
The request failed with HTTP status 401: Unauthorized.
I tried the same piece of code with WCF:
ServiceSoapClient client = new ServiceSoapClient();
client.ClientCredentials.Windows.ClientCredential = networkCredential;
return client.GetUserToken();
with these settings:
<binding name="ServiceSoap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
</security>
</binding>
Again, on the server, I can't get it to authenticate, from another machine connecting to this server, it works.
Here's the headers captured by advanced logging from the web service:
When it works:
sc-win32-status WWW-Authenticate Authorization
2147024891 "NTLM,Negotiate" -
0 - "Negotiate TlRMTVNTUAADAAAAGAAYAIoAAACi...."
When it fails, called from within the same server:
sc-win32-status WWW-Authenticate Authorization
2147024891 "NTLM,Negotiate" -
1073741715 "NTLM,Negotiate" "Negotiate ADAAAAGAAYAI4AAACiAaIBpgAAABoAGgBY..."
I also got this message instead of the plain 401 error, when I used WCF:
The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'NTLM,Negotiate'. ---> The remote server returned an error: (401) Unauthorized.
The explanation of Error 1073741715:
STATUS_LOGON_FAILURE (-1073741715 (0xC000006D))
The attempted logon is not valid. This is due to either an incorrect user name or incorrect authentication information.
Somehow my code is not authenticating to the web service correctly when it is run from within the server.
Here's a link to the same issue. The answer doesn't apply though:
401 Client 'Negotiate', Server 'Negotiate,NTLM' When Calling WCF Server to Server