Reputation:
I've written simple WCF service using netTcpBinding and security mode="Message" and clientCredentialType="UserName". Everything works fine when I pass valid username and password, session is established the way I wanted. However when the credentials are wrong exception is thrown though I can't catch it in my client application in try catch block. Did anyone have the same problem ? Here is my custom validator...
public class UserValidator : UserNamePasswordValidator
{
static int counter = 0;
public override void Validate(string userName, string password)
{
++counter;
Console.WriteLine(counter.ToString() + " " + DateTime.Now.ToShortTimeString());
if (userName != "test" || password != "test")
throw new FaultException("Bad username or password");
//throw new SecurityTokenException();
}
}
Upvotes: 2
Views: 2245
Reputation: 56520
Why aren't you throwing the security token exception? That's what it's there for. At that point a message has not be sent and the channel has not be opened, so you can't get a fault back.
Upvotes: 1
Reputation: 22743
Do you have code that sets up the channel between the client and server? If so, is the channel failing to be created correctly - as with message security the client and server must perform the hadnshake, both providing their credentials to open a security channel. This must be established before any further communications will be enabled, and the fact that invalid credentials are passed will stop the channel being created I suspect.
Upvotes: 0