.NET 调用 SharePoint Web 服务收到 HTTP 401 未经授权的异常
我正在尝试调用 SharePoint 列表服务来获取列表定义和数据。 SharePoint 网站是我的公司,但我无法控制它。以下是我对服务器安全性的了解:
服务器是 HTTPS:// 服务器在登录时接受 Windows Active Directory 凭据...
我尝试过 Basic、Digest、CredentialCache,只是 NetworkCredential、UnsafeAuthenticatedConnectionSharing、UseDefaultCredentials、PreAuthenticate...不确定正确的配置是什么...
我收到的错误是 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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此代码是否在与 SharePoint 相同的服务器上本地运行 - 如果是这样,那么它可能是本地环回检查 。
如果没有,那么您需要提供一些准确的详细信息 - 您的站点是否使用集成身份验证(如果是,是通过 NTLM 或 Kerberos)还是基本身份验证或表单?
另外 - 如果您尝试使用浏览器(以获取 WSDL)或 Web 服务测试工具(例如 SoapUI 或众多替代方案之一
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
我的网络应用程序是混合身份验证模式(声称 NTLM + FBA),下面的代码适用于我。
My web application is a mixed authentication mode (claims NTLM + FBA), below code works for me.