0

I am writing a quite simple WCF-service with username/password authentication. My code for the username/password validator looks like this:

public class InvoiceServiceUserValidation : UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {
        if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
        {
            throw new SecurityTokenException("Username and password required");
        }

        if (InvoiceServiceHelper.AuthenticateUser(userName, password)) return;

        throw new FaultException("Could not authenticate - Unknown reason");

    }
}

If I supply the correct username and password, everything is fine, and the operations continue. When I supply the wrong password, hovever, the exception is never returned, so my client just stays there waiting before it times out.

I have debugged so I know the line with "throw new FaultException" is actually reached when it is wrong, but still no answer to the client.

Help would be greatly appreciated

2 Answers2

0

you need to turn logging on for wcf. Once stuff passes the edges of your code you cant debug directly, logging however will get you a lot further into the problem. Especially when you start to use interception.

How to turn on WCF tracing?

when you have this you can look at the logs and figure out exactly what is happening. If you still cant figure it out id suggest asking a new question or else this will get put on hold.

what is your front end. Is it silverlight?

You say it is timing out - increase the time out to something silly like 10 mins. Does it timeout straight away.

is the connection being aborted, is fault code 500? fire up fiddler

Community
  • 1
  • 1
John Nicholas
  • 4,778
  • 4
  • 31
  • 50
  • In the trace it seems to me that the exception is thrown, but still the client does not receive it. There is a slight opportunity that I do not know how to read the trace file, however – sarcophilus Apr 30 '14 at 08:40
  • yeah they are hard. you can get traces on both sides of the boundary. – John Nicholas Apr 30 '14 at 08:55
  • How do I get traces on the client side? The same config lines in the app.config? – sarcophilus Apr 30 '14 at 08:56
  • basically yes. I haven't had to play with wcf for over a year so don't have any sample files to hand. I'd just have to google it. Search on here i bet there are about 50 questions asking the exact same thing. eg http://stackoverflow.com/questions/17591169/how-to-turn-on-wcf-tracing-at-the-client-side – John Nicholas Apr 30 '14 at 09:11
  • Nothing in the traces to help me, the only thing I can see is that the error is not caught on the client side... – sarcophilus Apr 30 '14 at 10:05
  • oh are you throwing the right exception? have you tried just throwing a normal exception or a securitytokenexception? – John Nicholas Apr 30 '14 at 11:21
0

I am not sure why, but when I switched to wsHttpBinding (From wsDualHttpBinding) this started working. It is not really a solution as much as a workaround, but that solved it for me.

If anyone else is struggling with the same, this may be the case.