title: .NET calling SharePoint Web Service gets an HTTP 401 Unauthorized exception
body: <p>I am trying to call a SharePoint Lists service to get list definition and data. The SharePoint site is my companies but I have no control over it. Here is all I know about the server's security:</p>
  
  <p>Server is HTTPS://
  Server accepts Windows Active Directory credentials when logging in...</p>
  
  <p>I have tried Basic, Digest, CredentialCache, just NetworkCredential, UnsafeAuthenticatedConnectionSharing, UseDefaultCredentials, PreAuthenticate... not sure what the proper config is...</p>
  
  <p>The error I receive is HTTP 401 Unauthorized.</p>
  
  <pre><code>                Uri url = new Uri(baseAddress + "/_vti_bin/Lists.asmx", UriKind.Absolute);
                  Lists.Lists client = new Lists.Lists();
  
                  // sometimes works
                  CredentialCache cache = new CredentialCache();
                  cache.Add(url, "NTLM", new NetworkCredential(context.UserName, context.Password, context.Domain));
                  client.UseDefaultCredentials = false;
                  client.Credentials = CredentialCache.DefaultCredentials;
                  // doesn't work ever
                  //client.Credentials = new NetworkCredential(context.UserName, context.Password, context.Domain);
                  //client.PreAuthenticate = true;
                  client.UnsafeAuthenticatedConnectionSharing = true;
                  client.Url = url.AbsoluteUri;
                  listData = client.GetList(listName).OuterXml;
  </code></pre>