WCF Service authentication messages - wcf

I'm writing a WCF service with authentication and have stumbled across this: I can't seem to define the messages returned in the event of an error in authentication (that is to say: user is not authenticated).
I have an IErrorHandler implementation in place, however that doesn't appear to catch the exceptions thrown (SecurityTokenException or FaultException<T>) during auth. I can confirm that it works in the rest of scenarios, however.
Is there something I'm missing here? Or is it really not possible to catch and handle exceptions thrown in auth?
Thanks

IErrorHandler can't handle the exception that happens in the authentication process. Why do you want to handle the authencation exception?
Your client side can catch the authentcation exception.

Related

WCF Message inspectors concurrency model

I have implemented message layer security using message inspector mechanism in a wcf service.
On the client side, in IClientMessageInspector.BeforeSendRequest I add an authentication header.
On the service side, in IDispatchMessageInspector.AfterReceiveRequest I inspect the authentication header in the message. If it is not found or as expected, I throw a SecurityException and try to log it to a database.
Here comes the interesting part. When logging to database, I try to read from this webservice again (this is web service which provides configuration info).
This is where the service stalls/deadlocks. I can see that the call to read configuration (when logging to db) is made, but I don't receive the call on the service. I keep getting a timedout exception every time.
After a little googling, I came across this post, which mentions that message inspectors are synchronous in nature. If that is so, how can I achieve what I am after?

Use WCF UserNamePasswordValidator with nServiceBus 5

I'm working on a WCF service where I created a custom UserNamePasswordValidator to validate the client. If username or password are wrong a FaultException is thrown.
I use nServiceBus 5 in the WCF service to send the client message to some internal systems.
The issue is that if a FaultException is thrown because the client hasn't access to the service, the client's request is processed anyway because (I guess) nServiceBus is handling the exception also if I'm not inside an handler.
The bus is started inside a custom ServiceHostFactory.
How could I tell to nServiceBus to don't handle that kind of Exception?

What does the WCF action stand for

What does the soap action http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault mean?
Found the solution.
WCF throws a fault code when it an exception is thrown.
Main issue is its not a SOAP xml response and thus many consuming applications do not know how to handle it.

Throwing exception from WCF Service without faulting

When throwing a FaultException from a WCF service, is there a way it can be thrown without faulting the actual connection? I'm looking to prevent an action for a particular method, but don't want to disrupt the client's connection (just return saying "you can't do this action right now, and here's why"). Or, is the required paradigm to recreate a new proxy in the .NET consuming app (in the case of .NET)
If you throw a FaultException then the client will get an exception but should be able to carry on using the same connection. If you let any other kind of exception out of the service (without having a Custom Error Handler in place) then it will fault the channel
Are you using .NET 4.0, can you use WebFaultException to return an HTTP status code with the appropriate error reason?

Adding new exception types to the WCF 4 routing service error handling

I am working on a prototype using WCF 4 routing services to create a pass through router, leveraging the error handling functionality
I have a requirement where if a WCF service generates a custom exception (in this scenario it is called a notPrimaryException), it should be handled in the same way as a communication exception is handled in WCF4 routing services error handling, that is, the message should be resent to the endpoints in the backup list.
Now I understand that this custom exception is returned from the service to the router as a fault exception at the message layer as opposed to a communication exception being returned at the transport layer.
I have tried using message inspectors and the IErrorHandler interface (ProvideFault and Handle Error) to identify if the notPrimaryException is occurring at the router but nothing is being picked up until it returns to the client as an unhandled fault exception. I was hoping to intercept this fault somewhere on the router and resend the message accordingly but I don't know if there are any appropriate behaviors.
Is there a way to shoehorn additional exception/fault types into the error handling infrastructure or is there another approach I may have overlooked?
Thanks and Regards,
Ivan
You should not be handling application errors on the router. Generally, the application developer has placed FaultExceptions on the service with the expectation of being able to handle them on the client.
If the FaultException is not received by the client, how does the client know what/anything went wrong?
The only errors you should be handling on the router are transport layer exceptions, application exceptions should be handled in the application.