title: Error calling web service 401: Unauthorized
body: <p>I get</p>
  
  <blockquote>
    <p><strong>The request failed with HTTP status 401: Unauthorized</strong></p>
  </blockquote>
  
  <p>My web service is .NET 4 running on IIS6. My client is .NET 2 running on IIS6</p>
  
  <p>When I run the both client and serivce on my local host it works.
  When I move the service to the web server I get the above error.  I have set Allow An</p>
  
  <p>I have tried every combination of anonymous access &amp; integrated Windows authentication within IIS
  I can access the web service via a brower and call it using Web Service Studio ok, it just does not work when I call from another .NET service</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have checked that the IUSR account has NTFS file permissions and is also added in local security policy as a USER that can access the server over network.</p>
  
  <p>When I call from WebService Studio it makes two request first called gets back 401, then it calls again passing 'Authorization' and works. See below.  So for some reason my anonymous access is not working. As when I only have anonymous access ticked and integrated Windows authentication unticked I cannot even access it from the brower</p>
  
  <pre><code>Content-Type: text/xml; charset=utf-8
  SOAPAction: "http://tempuri.org/HelloWorld"
  Host: webdev1
  Content-Length: 314
  Expect: 100-continue
  Connection: Keep-Alive
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;&lt;soap:Body&gt;&lt;HelloWorld xmlns="http://tempuri.org/"&gt;&lt;echo&gt;sd&lt;/echo&gt;&lt;/HelloWorld&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;
  
  HTTP/1.1 401 Unauthorized
  Content-Length: 1539
  Content-Type: text/html
  Server: Microsoft-IIS/6.0
  WWW-Authenticate: Negotiate
  WWW-Authenticate: NTLM
  Date: Thu, 28 Jun 2012 12:26:33 GMT
  Proxy-Support: Session-Based-Authentication
  </code></pre>
  
  <p>Call 2 (happens automatically)</p>
  
  <pre><code>POST http://webdev1/CSHRService/CSHR.asmx HTTP/1.1
  Content-Type: text/xml; charset=utf-8
  SOAPAction: "http://tempuri.org/HelloWorld"
  Authorization: Negotiate YIILzQYGKwYBBQUCoIILwTCCC72gJDAiB/EG1WyqaLj3E67GA0......
  Host: webdev1
  Content-Length: 314
  Expect: 100-continue
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;&lt;soap:Body&gt;&lt;HelloWorld xmlns="http://tempuri.org/"&gt;&lt;echo&gt;sd&lt;/echo&gt;&lt;/HelloWorld&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;
  HTTP/1.1 200 OK
  Date: Thu, 28 Jun 2012 12:26:34 GMT
  Server: Microsoft-IIS/6.0
  WWW-Authenticate: Negotiate oYGgMIGdoAMKAQChCwYJKoZIgvcSAQICooGIBI..
  X-AspNet-Version: 4.0.30319
  Cache-Control: private, max-age=0
  Content-Type: text/xml; charset=utf-8
  Content-Length: 360
  </code></pre>
  
  <p>My code that calls the service is just</p>
  
  <pre><code>  CSHRService cshrService = new CSHRService();
    string s = cshrService.HelloWorld("d");
  </code></pre>