views:

496

answers:

2

Hi

I am using Enterprise application block on my application' server side to handle exceptions.

I am able to successfully handle exception. I have created a custom service fault class to handle exceptions.

Here are my web config enteries...

<exceptionPolicies>
  <add name="WCF Exception Shielding">
    <exceptionTypes>
      <add type="TEST.Infrastructure.ExceptionHandling.Exceptions.TESTBusinessException, Pluto.Infrastructure.ExceptionHandling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      postHandlingAction="ThrowNewException" name="TESTBusinessException">
        <exceptionHandlers>
          <add logCategory="BusinessLoggingCategory" eventId="501" severity="Error"
            title="Pluto Service Exception" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
            priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Logging Handler" />
          <add
            type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="DefaultFaultContract Handler"
            faultContractType="TEST.Infrastructure.ExceptionHandling.Exceptions.TESTServiceException, Pluto.Infrastructure.ExceptionHandling"
            exceptionMessage="Pluto.Infrastructure.ExceptionHandling.Exceptions.TESTBusinessException {handlingInstanceID}">
            <mappings>
              <add name="Id" source="{Guid}"/>
              <add name="MessageText" source="{Message}"/>
            </mappings>
          </add>
        </exceptionHandlers>
      </add>

But on the client side when i try to catch this exception as

 catch (FaultException<TESTServiceException> fex) 
        { 
        }

this exception is not caught. I am able to get the exception message on the client side which i have writen in app.config on server side.

Can any one please help me figure out the problem.

Thanks in advance

Vikram

A: 

Have you defined fault contract on the operation ?

[FaultContract(typeof(TESTServiceException))]

Have you defined the [ExceptionShielding] attribute on the service contract ?

Also the following service behavior should be set

 <behaviors>
      <serviceBehaviors>
        <behavior name="StandardBehaviour">
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
 </behaviors>
Pratik
ServiceDebug value is already set to false...
Vikram I Code
[FaultContract(typeof(TESTServiceException))]and [ExceptionShielding] attributes have been correctly set.I am able to get exception message which i have set in my app.config. But my exception type is of System.ServiceModel.FaultException and not of the type System.ServiceModel.FaultException<TESTServiceException>
Vikram I Code
Only TESTBusinessException will be converted to FaultException<TESTServiceException>. Are you sure you are throwing the correct exception inside the operation ?Try doing just a throw new TESTBusinessException() from inside your operation and see what happens.
Pratik
+1  A: 

Try extracting the exception details using the XmlReader:

catch (FaultException ex)
{
    string msg = "FaultException: " + ex.Message;
    MessageFault fault = ex.CreateMessageFault();
    if (fault.HasDetail)
    {
        System.Xml.XmlReader reader = fault.GetReaderAtDetailContents();
        if (reader.Name == "TESTServiceException")
        {
            TESTServiceException detail = fault.GetDetail<TESTServiceException>();
            msg += "\n\nStack Trace: " + detail.SomeTraceProperty;
        }
    }
    MessageBox.Show(msg);
}

More explanation on catching fault exceptions here and here.

RaceFace