我知道有很多与此类似的问题,但我找不到针对此特定问题的问题。
先说几点:
- 我无法控制我们的 Sharepoint 服务器。我无法调整任何 IIS 设置。
- 我相信我们的 IIS 服务器版本是 IIS 7.0。
- 我们的 Sharepoint Server 正在通过 NTLM 预测请求。
- 我们的 Sharepoint Server 与我的客户端计算机在同一个域中。
- 我正在使用 .NET Framework 3.5、Visual Studio 2008
我正在尝试编写一个简单的控制台应用程序来使用 Sharepoint Web 服务来操作 Sharepoint 数据。我添加了服务参考,以下是我的 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),所以很遗憾这不是一个选项.
有什么帮助,伙计们?