我有一个简单的 .NET WPF 应用程序。我添加了服务参考。到
//服务器:端口/站点/site_collection_name/_vti_bin/lists.asmx
并将其称为 ListServ。我输入了以下代码
ListsSoapClient client = new ListsSoapClient();
if (client.ClientCredentials != null)
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
try
{
client.Open();
Console.WriteLine(client.State);
System.Xml.Linq.XElement listCollection = client.GetListCollection();
}
}
从 app.config
<binding name="ListsSoap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
上面的代码捕获了 CommunicationException:
System.ServiceModel.Security.MessageSecurityException:
The HTTP request is unauthorized with client authentication scheme 'Ntlm'.
The authentication header received from the server was 'NTLM'. --->
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication
HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory`1 factory)
我已经在共享点所在的 ISS 上启用了 Windows autentication。非常奇怪的是,我使用类似的代码成功地将文档添加到文档库。所有凭证都正确描述了在共享点列表中添加的文档。
我什至尝试过弃用:client.ClientCredentials.Windows.AllowNtlm = true;