1

Win8 Appを使用してSharePoint 2010リストのListItemを取得したいとします。Sharepoint 2010 WebListを持つGetListItems - DefaultNetworkCredentialsを使用したListSoapClient

BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); 
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; 

EndpointAddress endpoint = new EndpointAddress("http://site1/site2/_vti_bin/Lists.asmx"); 
string listName = "{4e661b3b-d0a9-4440-b98f-3f3ef41a44a7}"; 
string viewName = "{f1ba8d46-ad36-40ef-b4bc-6f74ea87b5d7}"; 
string rowLimit = "25";  
XElement ndQuery = new XElement("Query"); 
XElement ndViewFields = new XElement("ViewFields"); 
XElement ndQueryOptions = new XElement("QueryOptions"); 

MyService.ListsSoapClient client = new MyService.ListsSoapClient(basicHttpBinding, endpoint); 
client.ClientCredentials.Windows.ClientCredential.UserName = "user"; 
client.ClientCredentials.Windows.ClientCredential.Password = "pw"; 
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 


MyService.GetListItemsResponse response = await client.GetListItemsAsync(listName, viewName, ndQuery, ndViewFields, rowLimit, ndQueryOptions, null); 

私は、Windowsのログオンユーザーに資格情報を設定しようとする場合、私は、次の不正のエラーを取得:すべては、私は手動でのような資格情報を設定すると正常に動作します

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.

client.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; 

をすることができます助けて?

答えて

0

(代わりに、特定の使用既定の資格情報)、これを試してみてください。

private ListsSoapClient CreateListsSoapClient(string siteUrl, string siteUserName, string sitePassword) 
    {   
     var basicHttpBinding = new BasicHttpBinding 
     { 
      CloseTimeout = new TimeSpan(00, 5, 00), 
      OpenTimeout = new TimeSpan(00, 5, 00), 
      ReceiveTimeout = new TimeSpan(00, 5, 00), 
      SendTimeout = new TimeSpan(00, 5, 00), 
      TextEncoding = Encoding.UTF8, 
      MaxReceivedMessageSize = int.MaxValue, 
      MaxBufferSize = int.MaxValue, 
      Security = 
      { 
       Mode = BasicHttpSecurityMode.TransportCredentialOnly 
      }, 
      ReaderQuotas = 
      { 
       MaxArrayLength = int.MaxValue, 
       MaxBytesPerRead = int.MaxValue, 
       MaxStringContentLength = int.MaxValue 
      } 
     }; 

     basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;     

     var url = string.Format("{0}/_vti_bin/Lists.asmx", siteUrl); 
     var address = new EndpointAddress(url); 

     var listsSoapClient = new ListsSoapClient(basicHttpBinding, address); 

     listsSoapClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation; 
     listsSoapClient.ChannelFactory.Credentials.Windows.ClientCredential = new NetworkCredential(siteUserName, sitePassword); 
     listsSoapClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; 

     return listsSoapClient; 
    }