Avatar of PatrickK_W
PatrickK_W
Flag for United Kingdom of Great Britain and Northern Ireland asked on

HTTP status 401: Unauthorized when connectiong to webservice - cannot authenticate from localhost

Hi. Weird one. We have a webservice secured in an asp.net website that requires windows authentication. This has been working for about 3 year. Last week one of th guys did some messing around trying to install some SSL certificates, adding IP addresses, etc.
Since then, we cannot authenticate to the webservice from the local machine – ie:

We have a webservice on server1 in a website using host headers. If we try to call the
webservice from another site on this server in asp.net code (passing valid  credentials) it gives us a 401 error. If we try to access the webservice from server 2 using the same credentials it lets us in. It just cannot seem to authenticate on server 1 when called from server 1.

We setup the webservice on server2 with the exact same settings. If we call the webservice that is on server 2 form server 2 it works. If we call the webservices that is on server2 from server 1 that also works.

Server1->server1 – does not work – 401 error
Server1->server 2 works
Server2->server1 – works
Server2->server2 – works

The credentials being passed are the same for all calls. The credentials are the default credentials from the credential store. If we test to ensure we have a valid user, we do in all cases. We have also tried explicitly passing a username, password and domain as a new set of credentials witht eh exact same results (it works for all bar server1->server1).
Any ideas?
ASP.NETMicrosoft IIS Web ServerWCF

Avatar of undefined
Last Comment
PatrickK_W

8/22/2022 - Mon
PatrickK_W

ASKER
The calling code using default credentials
Dim ws As New filesdev.WebService
        Try
            ws.PreAuthenticate = True
            ws.Credentials = System.Net.CredentialCache.DefaultCredentials
            MessageBox.Show(ws.HelloWorld)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Open in new window

PatrickK_W

ASKER
or explicit credentials
Dim ws As New filesdev.WebService
        Try
            Dim cache As System.Net.CredentialCache = New System.Net.CredentialCache()
            cache.Add(New Uri(ws.Url), "Negotiate", New System.Net.NetworkCredential("username", "password", "ourdomain"))
            ws.Credentials = cache

            ws.PreAuthenticate = True
            ws.Credentials = cache
            MessageBox.Show(ws.HelloWorld)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Open in new window

PatrickK_W

ASKER
further to the above - we are using host headers for the site hosting the webservice. if we nmap localhost tothe site and call the webservice using localhost it all works properly. If we call it using the hostheader it still gives us 401 error.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
PatrickK_W

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PatrickK_W

ASKER
no other answers, plus fixed it mysefl