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:
Server is HTTPS:// Server accepts Windows Active Directory credentials when logging in...
I have tried Basic, Digest, CredentialCache, just NetworkCredential, UnsafeAuthenticatedConnectionSharing, UseDefaultCredentials, PreAuthenticate... not sure what the proper config is...
The error I receive is HTTP 401 Unauthorized.
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;
My web application is a mixed authentication mode (claims NTLM + FBA), below code works for me.
HttpWebRequest req = WebRequest.CreateHttp("https://example.com/");
req.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f"); //login with windows account
req.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequired;
req.Credentials = new NetworkCredential(“username", “password", "domain”);
//this also works
//req.Credentials = CredentialCache.DefaultNetworkCredentials;
Is this code running locally on the same server as SharePoint - if so then its probably the local loopback check.
If not then you need to give some acurate details - is your site using Integrated Authentication (and if so is it via NTLM or Kerberos) or Basic or Forms?
Also - what happens if you try to use that web service using a browser (to get the WSDL) or a web service test tool such as SoapUI or one of the many alternatives
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With