我知道在stackoverflow上有很多类似的问题,但是我找不到一个针对这个特定问题的解决方案。
首先有几点需要注意:
- 我对我们的Sharepoint服务器没有任何控制权,我无法调整任何IIS设置。
- 我相信我们的IIS服务器版本是IIS 7.0。
- 我们的Sharepoint服务器正在预期通过NTLM接收请求。
- 我们的Sharepoint服务器与我的客户端计算机在同一个域中。
- 我正在使用.NET Framework 3.5,Visual Studio 2008。
我试图编写一个简单的控制台应用程序,使用Sharepoint Web Services来操作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模拟程序
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();
}
这导致了相同的错误信息。
使用 security mode=TransportCredentialOnly
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" />
</security>
这导致出现了另一种错误消息:
The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: via
然而,我需要使用https协议,因此无法更改我的URI scheme。
我尝试过一些其他的组合方式,但我现在想不起来了,等我想起来后会发布它们。我真的快崩溃了。我在谷歌上看到很多链接都说“切换到Kerberos”,但是我的服务器似乎只接受NTLM,而不是“Negotiate”(如果它正在寻找Kerberos,它会显示为“Negotiate”),所以这不是一个选项。
有人能帮忙吗?