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

前端 未结 6 1614
孤街浪徒
孤街浪徒 2020-12-08 19:01

Few days ago I had quite a headache with authentication problems when using Windows authentication between client and wcf web service. The error I was getti

6条回答
  •  盖世英雄少女心
    2020-12-08 19:31

    For me the solution was besides using "Ntlm" as credential type:

        XxxSoapClient xxxClient = new XxxSoapClient();
        ApplyCredentials(userName, password, xxxClient.ClientCredentials);
    
        private static void ApplyCredentials(string userName, string password, ClientCredentials clientCredentials)
        {
            clientCredentials.UserName.UserName = userName;
            clientCredentials.UserName.Password = password;
            clientCredentials.Windows.ClientCredential.UserName = userName;
            clientCredentials.Windows.ClientCredential.Password = password;
            clientCredentials.Windows.AllowNtlm = true;
            clientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
        }  
    

提交回复
热议问题