Impersonation level not provided or invalid


  • I get an error while consuming the lists.asmx webservice. 
    The methods GetListCollection and GetList("ListName") are returning results without any problem.  When i call client.GetListItems(documentLibraryName, "All Items", null, null, null, null, null); it gives the following error:

     Server was unable to process request. ---> The type initializer for 'Microsoft.SharePoint.SoapServer.SoapServerException' threw an exception. ---> Could not load file or assembly 'System.Web.Services, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)

    My app.config:

                    <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="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
                        <security mode="Transport">  
                            <transport clientCredentialType="Ntlm" proxyCredentialType="None" 
                                realm="" /> 
                            <message clientCredentialType="UserName" algorithmSuite="Default" /> 
                <endpoint address="https://server/RD/_vti_bin/Lists.asmx" behaviorConfiguration="EndpointBehavior" 
                    binding="basicHttpBinding" bindingConfiguration="ListsSoap" 
                    contract="ListsService.ListsSoap" name="ListsSoap" /> 

    My Code:
    sharepointgetlistproject.ListsService.ListsSoapClient client = new sharepointgetlistproject.ListsService.ListsSoapClient("ListsSoap");  
                client.ClientCredentials.UserName.UserName = "DOMAIN\username";  
                client.ClientCredentials.UserName.Password = password; 

    I also tried to use clientCredentialType="Windows" but then i got an  "Unauthorized" error.

    What can be the problem here?

    Thanx in advance!
    Wednesday, February 25, 2009 1:23 PM


  • I've also been trying to get this working for a couple of hours. I finally cracked it.
    You need to allow your client endpoint to impersonate.
    Try adding the following to your <system.servicemodel>
                    <behavior name="ImpersonationBehavior">
                            <windows allowedImpersonationLevel="Impersonation"/>

    Now within the endpoint tag, set the following property: bindingConfiguration="ImpersonationBehavior"
    • Proposed as answer by Aceofspades25 Thursday, October 20, 2011 2:27 PM
    • Marked as answer by Rene vd O Tuesday, March 13, 2012 8:27 AM
    Thursday, October 20, 2011 2:27 PM