Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a publish - subscribe WCF Duplex model using NetTCpBinding (session mode). When a user is subscribing - I would like to pass in NetworkCredential - but I can't as it will not send the password and instead I see a '' (BLANK - Nada - nothing), but the username of course is there.. of course (MS! aargh).

I have a Simple Login and Authorization I want to do so they must be a valid user stored in the WCF Service Hosts private Database. (NOT a windows user etc..) I am not intending to send this info in the clear but I sure like the nice Credential Object - should I just simply use string Username, string Password, string Domain and create the Credential if I need to use it later. How will my Username and Password Data be encrypted - my NetTCpBinidng is included here as I am not sure how to configure that - the Host and the Client can be on different machines - and also can be on different networks.
Any help with this is Appreciated. Thank you.

C#
public void Subscribe(NetworkCredential credential)
{
    IGenericDataRepository<Users> repositorySingle = new GenericDataRepository<Users>(RepositoryConnection);
    Users UserList = repositorySingle.GetSingle(d => d.Name == credential.UserName && d.Password == credential.Password);
}

public NetTcpBinding SetNetTCPBinding()
{
    NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport);
    binding.Security.Mode = SecurityMode.Transport;
    binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
    binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
    binding.Security.Transport.ProtectionLevel = ProtectionLevel.None;
}
Posted

1 solution

Since I could not pass in the Credential, I used the channel factory ClientCredential Users field - my intellisense showed it was {get; set;} so I tried to use it and immediately got an exception declaring the field was readonly (and I said hogwash!). So I ended up with code like this in order to set it:

C#
ClientCredentials credentialBehaviour = NetPipeFactory.Endpoint.Behaviors.Find<ClientCredentials>();
credentialBehaviour.UserName.UserName = credentials.UserName;
credentialBehaviour.UserName.Password = credentials.Password;
// I found I could also do this..
credentialBehaviour.Windows.ClientCredential = Credential;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900