【发布时间】:2011-02-06 05:22:12
【问题描述】:
我知道关于 SO 有很多与此类似的问题,但我找不到针对此特定问题的问题。
先说几点:
- 我对我们的 Sharepoint 服务器无法控制。我无法调整任何 IIS 设置。
- 我相信我们的 IIS 服务器版本是 IIS 7.0。
- 我们的 Sharepoint 服务器正在通过 NTLM 预测请求。
- 我们的 Sharepoint Server 与我的客户端计算机位于同一域中。
- 我正在使用 .NET Framework 3.5、Visual Studio 2008
我正在尝试编写一个简单的控制台应用程序来使用 Sharepoint Web 服务来操作 Sharepoint 数据。我添加了Service Reference,下面是我的app.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ListsSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://subdomain.companysite.com/subsite/_vti_bin/Lists.asmx"
binding="basicHttpBinding" bindingConfiguration="ListsSoap"
contract="ServiceReference1.ListsSoap" name="ListsSoap" />
</client>
</system.serviceModel>
这是我的代码:
static void Main(string[] args)
{
using (var client = new ListsSoapClient())
{
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username", "password", "domain");
client.GetListCollection();
}
}
当我调用 GetListCollection() 时,会抛出以下 MessageSecurityException:
The HTTP request is unauthorized with client authentication scheme 'Ntlm'.
The authentication header received from the server was 'NTLM'.
带有内部 WebException:
"The remote server returned an error: (401) Unauthorized."
我尝试了各种绑定和各种代码调整来尝试正确验证,但无济于事。我将在下面列出。
我尝试了以下步骤:
在创建客户端之前使用本机 Win32 Impersonator
using (new Impersonator.Impersonator("username", "password", "domain"))
using (var client = new ListsSoapClient())
{
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("dpincas", "password", "domain");
client.GetListCollection();
}
这产生了同样的错误信息。
为我的客户端凭据设置 TokenImpersonationLevel
using (var client = new ListsSoapClient())
{
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
client.GetListCollection();
}
这产生了同样的错误信息。
使用安全模式=TransportCredentialOnly
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" />
</security>
这导致了不同的错误消息:
The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: via
但是,我需要使用 https,所以我无法更改我的 URI 方案。
我尝试了一些我不记得的其他组合,但我会在我记得的时候发布它们。到这里我真的是束手无策了。我在 Google 上看到很多链接说“切换到 Kerberos”,但我的服务器似乎只接受 NTLM,而不是“协商”(如果它正在寻找 Kerberos),所以很遗憾这不是一个选项.
有什么帮助吗,伙计们?
【问题讨论】:
标签: c# .net sharepoint authentication ntlm