I need to do a simple request against the People service in SharePoint 2010. Please tell me how I can do that. The following piece doesn't work.
public void Test() { var client = new Backend.PeopleService.PeopleSoapClient(); client.ClientCredentials.UserName.UserName = "domain\some.user"; client.ClientCredentials.UserName.Password = "passowrd"; var people = client.SearchPrincipals("", 1000, SPPrincipalType.All); } Error that I get is:
Test 'M:ShareShare.Tester.Test' failed: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'. System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. 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.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- End of inner exception stack trace ---
Updated on Aug 28, 2012
So this is what the config file looks like (after setting security mode="TransportCredentialOnly" and transport clientCredentialType="Ntlm")
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="PeopleSoap" 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="TransportCredentialOnly"> <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://portal.someserver.com/_vti_bin/People.asmx" binding="basicHttpBinding" bindingConfiguration="PeopleSoap" contract="Backend.PeopleService.PeopleSoap" name="PeopleSoap"> </endpoint> </client> </system.serviceModel> Now the error is
Test 'M:ShareShare.Tester.Test' failed: The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'. 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.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- End of inner exception stack trace ---
Updated 2
I deleted the config file and left just c# code for eliminating one moving part. So the code looks like this now:
public void Test() { var binding = new BasicHttpBinding(); binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm; var endpoint = new EndpointAddress("http://portal.someserver.com/_vti_bin/People.asmx"); var client = new Backend.PeopleService.PeopleSoapClient(binding, endpoint); var creds = client.ClientCredentials.Windows; creds.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation; creds.ClientCredential = new NetworkCredential("some.user", "password", "domain"); var people = client.SearchPrincipals("", 1000, SPPrincipalType.All); } This still gets me the same error about NTLM (see above).