我有一個簡單的.NET WPF應用程序。我添加了服務參考。到身份驗證到Sharepoint服務的NTLM失敗List.asmx但適用於copy.asm
//server:port/sites/site_collection_name/_vti_bin/lists.asmx
,並調用它羣發功能。我輸入代碼被跟隨
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)
我已經啓用了Windows autentication國際空間站上的SharePoint哪裏是。 非常奇怪的是,我使用類似的代碼來成功地將文檔添加到文檔庫。所有憑證正確描述在分享點列表上添加的文檔。
我甚至嘗試過棄用: client.ClientCredentials.Windows.AllowNtlm = true;
我解決了使用Web引用而不是使用服務引用的問題。爲什麼在「Copy.asmx」服務引用中的NTLM工作和「List.asmx」服務引用不是一個問題。 – AdrianX