WCF Exception policy mapping not working

Topics: Exception Handling Application Block
Jan 14, 2009 at 10:00 PM
Hello,
I am using Enterprise library 4.0 to use WCF Exception handling.(Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.dll 4.0.0.0)
My app.config file contains mapping like this :
<add source="{Message}" name="Message" />
<add source="{StackTrace}" name="StackTrace" />
<add source="{InnerException}" name="InnerException" />

My custom WCF exception class having properties like this :
[DataMember]
public string Message { get; set; }
[DataMember]
public string StackTrace { get; set; }
[DataMember]
public Exception InnerException { get; set; }

Now the thing is : Message and StackTrace properties are filled in with exception occured, but every time i get InnerException as null , though my original Exception has InnerException.

Is there a problem with Enterprise, that may be cannot cast to exception type?
what is the problem?
Jan 15, 2009 at 7:17 AM
Hi,

Would you mind posting your Service code? and your client code. 


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Jan 15, 2009 at 1:54 PM
Hi,
My service code :
App.config :
<exceptionHandling>
    <exceptionPolicies>
      <add name="CAS Exception Shielding">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException" name="Exception">
            <exceptionHandlers>
              <add exceptionMessage="fault exception occured" faultContractType="CASServiceWCF.CASFaultException, CASServiceWCF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.0.0.0, Culture=neutral"
                name="DefaultFaultContract Handler">
                <mappings>
                  <add source="{Message}" name="Message" />
                  <add source="{StackTrace}" name="StackTrace" />
                  <add source="{Id}" name="Id" />
                  <add source="{InnerException}" name="InnerException" />
                </mappings>
              </add>
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
Custom Exception Class :
[DataContract]
    public class CASFaultException
    {
        [DataMember]
        public string Message { get; set; }
        [DataMember]
        public string StackTrace { get; set; }
        [DataMember]
        public Guid Id { get; set; }
        [DataMember]
        public Exception InnerException { get; set; }
    }


Interface  Code :
[ServiceContract]
    [ExceptionShielding("CAS Exception Shielding")]
    public interface IMasterDataMaintenance
    {
        [OperationContract]
        [FaultContract(typeof(CASFaultException))]
        TimeResponse GetWeekendTimeList();
    }

Implementation Code :
public TimeResponse GetWeekendTimeList()
        {
            int j = 0; int i = 10 / j;
            return new CustomTimeList().GetWeekendTime();
        }


Client Code :
try
                {
                    proxy.GetWeekendTimeList();
                }
                catch (FaultException<CASFaultException> ex)
                {
                    MessageBox.Show(
                        ((ex.Detail.InnerException == null)?ex.Detail.Message : ex.Detail.InnerException.Message) +
                        "\n" + ex.Detail.StackTrace);
                }

I am getting ex.Detail.InnerException = null,always!!!

I am hosting WCF service in Web Service.
Jan 17, 2009 at 2:52 AM
What exception type do you expect in the InnerException?  Anyway, you may want to check out this page, detailed steps on how to integrate EHAB with WCF.

http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/04/07/Shielding-WCF-Services-with-Exception-Handling-Application-Block-_2D00_-Part-1.aspx


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com