Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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).

share|improve this question
    
    
I tried it, it didn't work (with the same exception that I posted in my last updated) –  bonomo Aug 28 '12 at 13:02
add comment

2 Answers

I think you need a config change, set:

security mode="TransportCredentialOnly"

and

transport clientCredentialType="Ntlm"

Should do the trick.

[Update in response]

Try passing your credentials using:

service.ClientCredentials.Windows.ClientCredential =
new System.Net.NetworkCredential("username", "password", "domain");

I am going to think some more...

share|improve this answer
    
thank you for the advice, it didn't work though, see my update –  bonomo Aug 28 '12 at 12:24
add comment

I have used list wcf service. and for that i used following code. it is working for me.

     ls = new ListsSoapClient();
     ls.Endpoint.Address = new EndpointAddress(url + "/_vti_bin/Lists.asmx");
     ls.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
     ls.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

compare your code with this code and try with this for people service.

follwing is my config file:

<system.serviceModel>
<bindings>
    <basicHttpBinding>
        <binding name="ListsSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
            receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
            <readerQuotas maxDepth="32" maxStringContentLength="8388608" maxArrayLength="16384"
                maxBytesPerRead="409600" maxNameTableCharCount="16384" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" />
          </security>
        </binding>                
    </basicHttpBinding>
</bindings>
<client>
    <endpoint address="http://server/_vti_bin/Lists.asmx" binding="basicHttpBinding"
        bindingConfiguration="ListsSoap" contract="ListColl.ListsSoap"
        name="ListsSoap" />            
</client>

share|improve this answer
    
See my updated answer. Your code didn't work either. Although though I tried TokenImpersonationLevel.Impersonation. –  bonomo Aug 28 '12 at 13:45
    
have u updated your code with referencing this two line also: ls.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; ls.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; –  Ravi Suthar Aug 28 '12 at 13:46
    
Ok, I just tried with the following and I got the same exception: creds.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; creds.ClientCredential = CredentialCache.DefaultNetworkCredentials; –  bonomo Aug 28 '12 at 14:06
    
also change in config file as above told you –  Ravi Suthar Aug 28 '12 at 14:09
    
Just copied your config over mine and did what you said with the c# part. Still no luck. Same NTLM error. –  bonomo Aug 28 '12 at 14:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.