I have an existing WCF service(A) that is using custom user validation. I need to write another WCF service(B) that will work as proxy between client and existing WCF service(A). Is it a way how to get access to:
ClientCredentials.UserName.UserName
ClientCredentials.UserName.Password
How to get access to credentials on B and pass it to A? Example of B service:
public class WcfServiceB: IWcfServiceB
{
private WcfServiceA _serviceA;
public WcfServiceB()
{
_serviceA = new WcfServiceA();
_serviceA.ClientCredentials.UserName.UserName = userName; //how to get current userName of WcfServiceB??
_serviceA.ClientCredentials.UserName.Password = password; //how to get current password of WcfServiceB??
}
public string TestMethod()
{
return _serviceA.TestMethod();
}
}
UPD: How I achived the result:
I created a custom validation class with static fields for UserName and Password
public class CustomUserCredentials : UserNamePasswordValidator
{
public static string UserName;
public static string Password;
public override void Validate(string userName, string password)
{
UserName = userName;
Password = password;
}
}
Then in my WcfServiceB I used these user credentials to pass them to the reference service:
public class WcfServiceB: IWcfServiceB
{
private WcfServiceA _serviceA;
public WcfServiceB()
{
_serviceA = new WcfServiceA();
_serviceA.ClientCredentials.UserName.UserName = CustomUserCredentials.UserName;
_serviceA.ClientCredentials.UserName.Password = CustomUserCredentials.Password;
}
public string TestMethod()
{
return _serviceA.TestMethod();
}
}
Maybe it's not the best implementation, but helped me to achive the result.
If you need to use a windows domain user password for authentication, you can use WSHttpBinding. Also set the Security.Mode property to Message and use the X509 certificate to encrypt the password sent from the client to the server.
Calling the service delivery client and password can be written as follows:
1.The client application must prompt the user for his user name and password.
2.Creates an instance of the client proxy to specify the client's certificate.