How to specify allowed exceptions in WCF's configuration file?

Posted by tucaz on Stack Overflow See other posts from Stack Overflow or by tucaz
Published on 2010-05-11T11:18:05Z Indexed on 2010/05/11 11:44 UTC
Read the original article Hit count: 237

Filed under:
|
|
|
|

Hello!

I´m building a set of WCF services for internal use through all our applications. For exception handling I created a default fault class so I can return treated message to the caller if its the case or a generic one when I have no clue what happened.

Fault contract:


    [DataContract(Name = "DefaultFault", Namespace = "http://fnac.com.br/api/2010/03")]
    public class DefaultFault
    {           
        public DefaultFault(DefaultFaultItem[] items)
        {
            if (items == null || items.Length== 0)
            {
                throw new ArgumentNullException("items");
            }

            StringBuilder sbItems = new StringBuilder();

            for (int i = 0; i 

Specifying that my method can throw this exception so the consuming client will be aware of it:

        [OperationContract(Name = "PlaceOrder")]
        [FaultContract(typeof(DefaultFault))]
        [WebInvoke(UriTemplate = "/orders", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "POST")]
        string PlaceOrder(Order newOrder);

Most of time we will use just .NET to .NET communication with usual binds and everything works fine since we are talking the same language. However, as you can see in the service contract declaration I have a WebInvoke attribute (and a webHttp binding) in order to be able to also talk JSON since one of our apps will be built for iPhone and this guy will talk JSON.

My problem is that whenever I throw a FaultException and have includeExceptionDetails="false" in the config file the calling client will get a generic HTTP error instead of my custom message.

I understand that this is the correct behavior when includeExceptionDetails is turned off, but I think I saw some configuration a long time ago to allow some exceptions/faults to pass through the service boundaries.

Is there such thing like this? If not, what do u suggest for my case?

Thanks a LOT!

© Stack Overflow or respective owner

Related posts about wcf

Related posts about exception