xkcd
xkcd

Reputation: 2590

Using Windows Authenticated WCF services

I have a Windows authenticated WCF service.

Using the following configuration:

BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

binding.SendTimeout = TimeSpan.FromMinutes(60);
binding.CloseTimeout = TimeSpan.FromMinutes(60);
binding.OpenTimeout = TimeSpan.FromMinutes(60);
binding.ReceiveTimeout = TimeSpan.FromMinutes(60);

NexumCrmServiceClient client = new NexumCrmServiceClient(binding, new EndpointAddress("http://xxxxxx:81/xxxxxxxxxxxxxx.svc"));
client.ClientCredentials.Windows.AllowNtlm = true;
//client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("xxxxxxxx", "xxxxxxxx", "xxxxxxxxx");

I'm getting this error:

There was no endpoint listening at http://xxxxxx:81/xxxxxxxxxxxxxxxx.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details...

And if I use the configuration below:

BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;

binding.SendTimeout = TimeSpan.FromMinutes(60);
binding.CloseTimeout = TimeSpan.FromMinutes(60);
binding.OpenTimeout = TimeSpan.FromMinutes(60);
binding.ReceiveTimeout = TimeSpan.FromMinutes(60);

NexumCrmServiceClient client = new NexumCrmServiceClient(binding, new EndpointAddress("http://xxxxxx:81/xxxxxxxxxxxxxx.svc"));
client.ClientCredentials.Windows.AllowNtlm = true;
//client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("xxxxxxxx", "xxxxxxxx", "xxxxxxxxx");

I'm getting another error:

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

Would you please suggest a configuration that works successfully?

Thanks in advance,

Upvotes: 5

Views: 8682

Answers (1)

Sixto Saez
Sixto Saez

Reputation: 12680

I believe you need to set:

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows

to get what your question title is referring to. Also, review this MSDN article on using Windows authentication with basicHttpBinding.

Upvotes: 6

Related Questions