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

后端 未结 10 2235
滥情空心
滥情空心 2020-12-01 00:21

I know there\'s a lot of questions on SO similar to this, but I couldn\'t find one for this particular issue.

A couple of points, first:

  • I have n
10条回答
  •  春和景丽
    2020-12-01 00:48

    Visual Studio 2005

    1. Create a new console application project in Visual Studio
    2. Add a "Web Reference" to the Lists.asmx web service.
      • Your URL will probably look like: http://servername/sites/SiteCollection/SubSite/_vti_bin/Lists.asmx
      • I named my web reference: ListsWebService
    3. Write the code in program.cs (I have an Issues list here)

    Here is the code.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Xml;
    
    namespace WebServicesConsoleApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    ListsWebService.Lists listsWebSvc = new WebServicesConsoleApp.ListsWebService.Lists();
                    listsWebSvc.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    listsWebSvc.Url = "http://servername/sites/SiteCollection/SubSite/_vti_bin/Lists.asmx";
                    XmlNode node = listsWebSvc.GetList("Issues");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
    }
    

    Visual Studio 2008

    1. Create a new console application project in Visual Studio
    2. Right click on References and Add Service Reference
    3. Put in the URL to the Lists.asmx service on your server
      • Ex: http://servername/sites/SiteCollection/SubSite/_vti_bin/Lists.asmx
    4. Click Go
    5. Click OK
    6. Make the following code changes:

    Change your app.config file from:

    
        
        
    
    

    To:

    
      
    
    

    Change your program.cs file and add the following code to your Main function:

    ListsSoapClient client = new ListsSoapClient();
    client.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
    client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
    XmlElement listCollection = client.GetListCollection();
    

    Add the using statements:

    using [your app name].ServiceReference1;
    using System.Xml;
    

    Reference: http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list

提交回复
热议问题