Windows WCF Credentials

my client on server A calls a service on B, which calls a service on C.
To get a call from B-> C, I have to do this:

channel.Credentials.Windows.ClientCredential = 
   new System.Net.NetworkCredential("WndowsUserName", "WindowsPassWord");  
IService1 service = channel.CreateChannel();  

etc...

the username and password are the Windows credentials used from A-> B Of course I don't want to do it hard, so how can I do it without hardcoding?

I tried, no luck:

WindowsIdentity callerWindowsIdentity = 
    ServiceSecurityContext.Current.WindowsIdentity;  
using (callerWindowsIdentity.Impersonate())  
+3
source share
3 answers

Use

System.Net.CredentialCache.DefaultNetworkCredentials

properties. It provides authentication credentials for the current security context in which the application is running. Details can be found here .

+2
source

,

System.Net.CredentialCache

... DefaultCredentials DefaultNetworkCredentials, . , ( ). ,

AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.WindowsPrincipal);

.

Then, when you initialize the WCF service, you can use the DefaultNetworkCredentialsone provided CredentialCache.

channel.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
IService1 service = channel.CreateChannel();
0
source

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


All Articles