本文介绍了.NET调用的SharePoint Web服务得到一个HTTP 401未授权异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调用一个SharePoint列表服务来获取列表定义和数据。 SharePoint网站是我的公司,但我有没有对其进行控制。这是我所知道的有关服务器的安全性:

服务器为https://登录时... Server接受Windows活动目录凭据

我已经试过基本,摘要,CredentialCache,刚刚的NetworkCredential,UnsafeAuthenticatedConnectionSharing,UseDefaultCredentials,preAuthenticate ...不知道正确的配置是什么...

我收到的错误是HTTP 401未经授权。

 开放的URL =新的URI(baseAddress +/_vti_bin/Lists.asmx,UriKind.Absolute);
                Lists.Lists客户端=新Lists.Lists();

                //有时工作
                CredentialCache缓存=新CredentialCache();
                cache.Add(URL,NTLM,新的NetworkCredential(context.UserName,context.Password,context.Domain));
                client.UseDefaultCredentials = FALSE;
                client.Credentials = CredentialCache.DefaultCredentials;
                //不起作用不断
                //client.Credentials =新的NetworkCredential(context.UserName,context.Password,context.Domain);
                //client.$p$pAuthenticate = TRUE;
                client.UnsafeAuthenticatedConnectionSharing = TRUE;
                client.Url = url.AbsoluteUri;
                的ListData = client.GetList(LISTNAME).OuterXml;
 

解决方案

这是code包括SharePoint在同一台服务器上本地运行 - 如果是的话,它可能是的。

如果没有,那么你需要给一些acurate的细节 - 是使用集成身份验证您的网站(如果是通过NTLM或Kerberos是)或基本或表单

另外 - 如果您尝试使用浏览器(获取WSDL)或Web服务测试工具,如的或的许多选择

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;

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

这篇关于.NET调用的SharePoint Web服务得到一个HTTP 401未授权异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:58