Windows Authentication with basicHttpBinding for WCF

I am very annoyed by this in the last 2 hours :(

People,

I am trying to access a SharePoint OOTB list web service from a console application. My SharePoint site in IIS is set to native Windows Auth mode, and anonymous access is disabled.

Now on the client side what I am doing is as follows

try            
{
   BasicHttpBinding bind = new BasicHttpBinding();
   bind.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
   bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
   EndpointAddress endpoint = new EndpointAddress("http://abc:37379/_vti_bin/lists.asmx");
   ServiceReference1.ListsSoapClient listService
       = new ConsoleApplication1.ServiceReference1.ListsSoapClient(bind, endpoint);
   var elm = listService.GetListItems("Tasks", null, null, null, "10", null, @"06dc3b48-a55e-4db8-8511-acbaf9748e15");
}
catch (Exception ex){
  Console.WriteLine("Message:\n" + ex.Message + "\nDetail:\n" +
  ex.ToString() + "\nStackTrace:\n" + ex.StackTrace);   }

Boom, this throws an exception “The HTTP request is not authorized using the Negotiate client authentication scheme. The authentication header received from the server was“ NTLM ”.

I really wanted to do something like what we did on the old network 2.0 days

serviceProxy.Credentials = new NetworkCredentials("username","password","domain");

What is the easiest way to achieve this kind of credential processing in new proxy classes?

(, , Binding/endpoint , , . , , ).

- ? .

+3
1

IIRC , - ntlm, kerberos (windows) .

bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;

kerberos, , - , .

, factory , , factory. :

var cf = new ChannelFactory<IServiceInterface>(
    bind, endpoint);
cf.Credentials.UserName.UserName = "domain\\someuser";
cf.Credentials.UserName.Password = "password";
+3

Source: https://habr.com/ru/post/1711082/


All Articles