3

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)

Stealth Rabbi
  • 10,156
  • 22
  • 100
  • 176

2 Answers2

2

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

Richard Blewett
  • 6,089
  • 1
  • 18
  • 23
  • I've thus far only thrown a fault exception form my customer credentials validator class. Upon receipt, the connection is faulted. Would throwing a fault exception from a contract method not fault it, as you've stated? – Stealth Rabbi Apr 20 '12 at 11:55
  • If this is a custom username/password validator then you should only throw a SecurityTokenValidationException. If you throw the FaultException from the contract method (or use a custom error handler) then you will not fault the channel – Richard Blewett Apr 20 '12 at 18:43
  • I realize this is not my original question, but this MSDN article indicates to throw a FaultException from the validator. When I do this, the connection is fauled (which is the behavior the client app expects). This is why I though throwing a FaultException from a service contract method would behave similarly. http://msdn.microsoft.com/en-us/library/aa702565.aspx – Stealth Rabbi Apr 23 '12 at 14:12
  • However, your answer regarding throwing FaultException and it not faulting the client connection is correct, so I'm marking this answered. thanks. – Stealth Rabbi Apr 23 '12 at 15:14
0

Are you using .NET 4.0, can you use WebFaultException to return an HTTP status code with the appropriate error reason?

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173