2013-05-22 38 views
0

我有一個簡單的.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;

回答

0

我用Web Reference替換了Service Reference,它起作用。

0

如果您嘗試從另一個服務器場調用此Web服務,您將遇到雙跳問題,解釋爲here。基本上,NTLM無法知道SharePoint用戶的Windows憑據是什麼。你可以通過這個圍繞:

  • 硬編碼的憑據,
  • 允許匿名訪問,或
  • 設置Kerberos身份驗證。
+0

我解決了使用Web引用而不是使用服務引用的問題。爲什麼在「Copy.asmx」服務引用中的NTLM工作和「List.asmx」服務引用不是一個問題。 – AdrianX