Question

Our company is making the switch from Microsoft.Practices.Enterprise.Library logging and exception handling to using Log4Net. I removed all of the standard logging and exception handling calls, replacing them with the Log4Net equivalents, but when I removed the Practices Dlls, I noticed that we were using them for ExceptionShielding:

using System;
using System.ServiceModel;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF;

namespace CRM.WCFServices.LeadIntegration.ServiceContracts
{
    /// <summary>
    /// Interface for systems external to CRM to interact with outbound calls.
    /// </summary>
    [ExceptionShielding("WCF Exception Shielding")]
    [ServiceContract]
    public interface IOutboundIntegrationService
    {
        #region Contracts

        [OperationContract]
        [FaultContract(typeof (Common.Services.WCF.FaultContracts.ServiceFault))]
        void SendOutboundData(string entityName, Guid entityId, DateTime modifiedOn, Guid modifiedBy,
                              string crmOrganization);

        #endregion
    }
}

The basic question is "How can I safely remove it?" which involves answering most of these questions:

  1. What does it do? - From What I've read it allows you to catch any exceptions in your WCF Service before it is returned to the client, allowing you to log the exception and create an exception that doesn't contain any security sensitive information.
  2. Is it valid on an Interface (it's not referenced anywhere on the ?
  3. Does Log4Net have something similar?
Was it helpful?

Solution

If I remember correctly, the purpose of the Exception Shielding feature was to

  1. Prevent the release of implementation detail across the service boundary, or
  2. Allow the developer to be lazy and not add try/catch blocks around all service operations at the service boundary.

Make your choice.

If my memory is correct, then all you need to do is either turn includeExceptionDetailInFaults to false in the web.config, or to put try/catch blocks around your service methods:

try
{
    // service code
}
catch (Exception ex)
{
    // Log the exception
    throw new FaultException("Unknown service failure");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top