0

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?

EvilDr
  • 8,943
  • 14
  • 73
  • 133

1 Answers1

2

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.

Community
  • 1
  • 1
Big Daddy
  • 5,160
  • 5
  • 46
  • 76
  • Superb, thank you. I am including a reference to the SOAP Fault documentation for reference: http://www.w3.org/TR/soap12-part0/#L11549 I'll define a class with the DataContract attribute, and then throw a FaultException(Of MyClass). Does it matter what fields I put in MyClass, e.g. ErrorCode, ErrorDetail etc. please? Also should they have a specific name, for example names matching the SOAP Fault documentation -> message and errorcode – EvilDr Dec 17 '12 at 15:51
  • 1
    Good...you can name the fields anything you like and have them contain as much or a little data as makes sense for your needs. You just need to be careful not to expose sensitive data, such as server names, database names, etc. Trying to keep your naming convention in-line with industry naming standards is always a good idea. Good luck. – Big Daddy Dec 17 '12 at 16:09
  • Many thanks. Please keep your eyes open for more of my questions in the near future... :-) – EvilDr Dec 18 '12 at 08:44