ExceptionShielding有更好的替代品吗?

时间:2013-12-18 19:34:11

标签: c# wcf enterprise-library

我们公司正在从Microsoft.Practices.Enterprise.Library日志记录和异常处理切换到使用Log4Net。我删除了所有标准的日志记录和异常处理调用,用Log4Net等效替换它们,但是当我删除了Practices Dlls时,我注意到我们将它们用于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
    }
}

基本问题是“我该如何安全地将其删除?”这涉及回答大部分问题:

  1. 它做什么? - 从我读过的内容中,它允许您在WCF服务返回到客户端之前捕获它们中的任何异常,允许您记录异常并创建不包含任何安全敏感信息的异常。
  2. 它在接口上是否有效(它没有在?
  3. 上的任何地方引用
  4. Log4Net有类似之处吗?

1 个答案:

答案 0 :(得分:1)

如果我没记错的话,Exception Shielding功能的目的是

  1. 防止跨服务边界发布实现细节,或
  2. 允许开发人员延迟,不要在服务边界的所有服务操作周围添加try / catch块。
  3. 做出选择。

    如果我的记忆是正确的,那么您需要做的就是在web.config中将includeExceptionDetailInFaults设置为false,或者在您的服务方法周围放置try / catch块:

    try
    {
        // service code
    }
    catch (Exception ex)
    {
        // Log the exception
        throw new FaultException("Unknown service failure");
    }
    
相关问题