I’m just developing my first WCF WebMethod, and am looking at error handling.
After having spent a week reading up on this, the general consensus seems to be that errors within WCF WebMethods should be thrown as either WebFaultException, or FaultException. Furthermore, many tutorials teach that using FaultException(Of T) provides even better functionality. This seems straightforward enough…
I then found a source stating that throwing CLR Exceptions is not good when the WebMethod is being consumed by a non-.NET application, e.g. Java etc, and that a SOAP Fault should be used.
Can someone please clarify whether the logic is built-into WCF 4.5 to automatically convert FaultException and FaultException(Of T) to a SOAP fault that can be processed/understood by external systems?
In general, how do other people communicate errors to external systems please?
If you use FaultException(Of T), it will interop with other SOAP technologies like Java. This SO post explains it – WCF/WebService: Interoperable exception handling. This is how I’ve done it for Java clients. Let me know if you need more detail.