How to pass default credentials in Windows Authentication

Viewed 10366

I'm developing UWP application using C#.net and it has WCF service with Windows Authentication enabled. I struggling to pass default NetworkCredential after consume a service call using Add service reference option.

Please find below my examinations.

When I pass correct windows authentication credentials, it is working as expected.

var service = new ServiceReference.Service1Client();
service.ClientCredentials.Windows.ClientCredential =new NetworkCredential("pradeep","****");
var test = await service.GetDataAsync(1);

but, I wanted pass default network credentials while using my service methis

var service = new ServiceReference.Service1Client();
service.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
var test = await service.GetDataAsync(1);

I also tried below option.

service.ClientCredentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials;

When I pass default credentials. I'm getting below exception.

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

I tested same service call with default NetworkCredential in WPF application which is working as expected.

1 Answers
Related