I need to return a fault of specific type from a WCF service so that the client can catch FaultException<MyClass>
. In order to do this, as far as I know, only way out is to apply the FaultContract(typeof(MyClass))
at the operation level. Is there any other way to do this at a global level? One place where I can add this contract to all operations in all services?
Asked
Active
Viewed 899 times
0

Badrinarayanan Lakshmiraghavan
- 19,159
- 4
- 62
- 61
-
You can vote for adding this feature: https://connect.microsoft.com/VisualStudio/feedback/details/343148/allow-faultcontractattribute-to-be-specified-on-a-servicecontract-interface – Joe May 05 '14 at 05:33
-
Possible duplicate of [WCF: Same Faultcontract on many methods](http://stackoverflow.com/questions/1392556/wcf-same-faultcontract-on-many-methods) Funny fact: Both has wrong marked answer :-) – Kobor42 Jan 24 '17 at 18:14
2 Answers
2
Unfortunately you need to add it at every operation, however you can use tools like PostSharp that will re-write your code on compile so you could create an attribute that you put on a contract and have PostSharp add the correct FaultContract
attribute on each OperationContract
.

Scott Chamberlain
- 124,994
- 33
- 282
- 431
0
Yea...I wish we can just globally define the default FaultException for the service level, then override for specific messages. I'm on a WSDL first project and the WCF WSDLs come out looking FUGLY!

Cyberpass
- 1,145
- 1
- 7
- 13