Exception Shielding eating Fault Contracts

Topics: Exception Handling Application Block, General discussion
Apr 2, 2008 at 11:29 PM
I have implemented Exception Shielding using Ent Lib 3.1 with WSSF Modeling Edition VS 2008. The Exception Shielding is working great but a little to great. Not only is it shielding Sytem.Exception but also shielding all my Fault Contracts. Using WCF Exception Shielding on Exception Type System.Exception. Have an Operation called Get() which has two FaultContracts associated with it.
WCF::FaultContract(typeof(CriteriaNotSuppliedFault))
WCF::FaultContract(typeof(SystemFault))
GetResponse Get(GetRequest request);
SystemFault is used in the Fault Contract Exception Handler to map all System.Exception to the Fault Contract SystemFault, where SystemFault contains a member called ID of type Guid.
My problem is when I go to throw my Fault Contract
CriteriaNotSuppliedFault oFault = new CriteriaNotSuppliedFault();
oFault.Message = "Please enter a City & State or a ZIP Code.";
throw new System.ServiceModel.FaultException<CriteriaNotSuppliedFault>(oFault);
It gets ExceptionShielded. User ends up with
catch (System.ServiceModel.FaultException<ListingManagementProxy.SystemFault> systemFault)
{
WriteMessage("SystemFault:" + "An error has occurred while consuming Web service. ErrorId: " + systemFault.Detail.ID);
}
Anyone have any idea why Fault Contracts are being Shielded?
Jun 5, 2008 at 10:07 PM
I am facing the similar issue.. Could you please share with us if you are able to resolve the issue/ work around
Jun 17, 2008 at 9:09 AM
This is still happening with EntLib 4 EHAB.

I'm using EHAB ExceptionShielding and also the Validation Application Block (VAB) to validate inputs to my WCF service. I've configured a catch all exception handler in the EHAB that should map all exceptions derived from System.Exception to a generic fault contract - MyWcfGenericFault.

When ExceptionShielding is turned off (by either commenting out the [ExceptionShielding] attribute or setting <serviceDebug incluldeExceptionDetailsInFaults="True" />) when the VAB spots a validation error it automatically raises a FaultException and the client gets the FaultException<ValidationFault> as expected.

When ExceptionShielding is turned on the the client gets my shielded exception MyWcfGenericFault.

Therefore, not only is the EHAB shielding exceptions, its also shielding FaultExceptions. Is there some way round this?
Jun 17, 2008 at 4:25 PM
Edited Jun 17, 2008 at 4:27 PM
Hi,

You can define an entry in the WCF policy for FaultException, with no handlers and None as the action. This will make the handler specified for Exception ignore the fault exception, and the shielding error handler will just let it through.

[edited to add the config snippet]

    7   <exceptionHandling>

    8     <exceptionPolicies>

    9       <add name="WCF Exception Shielding">

   10         <exceptionTypes>

   11           <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

   12             postHandlingAction="ThrowNewException" name="Exception">

   13             <exceptionHandlers>

   14               <add exceptionMessage="Test" faultContractType="ShieldingTest.TestFaultContract, ShieldingTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

   15                 type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

   16                 name="Fault Contract Exception Handler" />

   17             </exceptionHandlers>

   18           </add>

   19           <add type="System.ServiceModel.FaultException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

   20             postHandlingAction="None" name="FaultException" />

   21         </exceptionTypes>

   22       </add>

   23     </exceptionPolicies>

   24   </exceptionHandling>



Hope this helps,
Fernando


bigal wrote:
This is still happening with EntLib 4 EHAB.

I'm using EHAB ExceptionShielding and also the Validation Application Block (VAB) to validate inputs to my WCF service. I've configured a catch all exception handler in the EHAB that should map all exceptions derived from System.Exception to a generic fault contract - MyWcfGenericFault.

When ExceptionShielding is turned off (by either commenting out the [ExceptionShielding] attribute or setting <serviceDebug incluldeExceptionDetailsInFaults="True" />) when the VAB spots a validation error it automatically raises a FaultException and the client gets the FaultException<ValidationFault> as expected.

When ExceptionShielding is turned on the the client gets my shielded exception MyWcfGenericFault.

Therefore, not only is the EHAB shielding exceptions, its also shielding FaultExceptions. Is there some way round this?


Jun 18, 2008 at 4:21 PM
You're a genius - thanks - now works perfectly!
Aug 28, 2008 at 7:20 PM
I tried to add an entry in the WCF policy for FaultException as describe above, but now when there is a validation fault from the server, the client receives a CommunicationException.  Another thing I noticed is that while my custom validation still works, all of the built-in validations from the Validation block such as NotNullValidator no longer works.  Does anyone have any idea?

Thanks!
Aug 29, 2008 at 3:24 PM
Hi,

Can you post a repro project and the details of the CommunicationException?

Fernando
Jan 30, 2011 at 12:09 PM

Hi,

I am using the EnLib4.1 .

I have EHAB

 <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="XPlatform Service Category" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add source="XPlatform ServiceLibrary Log" formatter="Text Formatter"
        log="XPlatform" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Formatted EventLog TraceListener" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="XPlatform Service Category">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="Exception Policy">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow" name="Exception">
            <exceptionHandlers>
              <add logCategory="XPlatform Service Category" eventId="100" severity="Error"
                title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                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" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
      <add name="WCFShielding">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException" name="Exception">
            <exceptionHandlers>
              <add logCategory="XPlatform Service Category" eventId="100" severity="Error"
                title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                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 exceptionMessage="&quot;Pappu!!!&quot;" faultContractType="SyncSoft.XPlatform.V1.Security.UnauthorizedAccessFault, XPlatform Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1f4d9fa9b4928bac"
                type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="Throw UnauthorizedAccessFault">
                <mappings>
                  <add source="{Guid}" name="Id" />
                  <add source="{Message}" name="Message" />
                </mappings>
              </add>
            </exceptionHandlers>
          </add>
          <add type="System.ServiceModel.FaultException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="None" name="FaultException" />
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
 

 

Whe I use wcfTestClient to test fault exception by throwing new exception in service (as  throw new DivideByZeroException("Invalid!!"), it is try/catch block and identifying it as fault exception properly.

             try
            {
                var response = client.SubmitReceiptBatch(request);
            }
            catch (FaultException<UnauthorizedAccessFault> ex)
            {
                UnauthorizedAccessFault fault = ex.Detail;
                Console.WriteLine(fault.Message);
            }

 

but when I integrate and test the same with with the screens, it says:

No signature message parts were specified for messages with the 'SyncSoft.CapitalX.V8.Services.FieldOptionService.MessageContracts/IFieldOptionService/GetFieldOptionsUnauthorizedAccessFaultFault' action.

Can you please help me in this regard.

Regards, Padma

Jan 31, 2011 at 12:48 AM

I replied to your other thread.

 

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