Reputation: 1300
Is there a good way to throw exceptions from a WCF service that is exposed both as a RESTful service and SOAP service? From what I have gathered so far, SOAP service should throw FaultExceptions and RESTful service should throw WebProtocolException for the error details to be easily available at client side. In my case, the same service is exposed through 2 endpoints - RESTful and SOAP. What kind of exception handling mechanism should I use so I can pass error details easily to both RESTful clients and SOAP clients?
Upvotes: 0
Views: 1075
Reputation: 42669
SOAP and REST are two different mechanism for exposing service functionality and the way exception get exposed in SOAP and REST also differs as you have detailed correctly.
REST or REST over HTTP is a architectural pattern and it embraces HTTP as a protocol. Exception in your application should get translated into HTTP error code such as 40x, 50x etc. For example
Details of the error can be returned together with the error code in the response body.
Client using RESTful endpoint should expect HTTP error code and should handle them.
Upvotes: 1