Entlib自定义异常处理程序缺少映射

时间:2015-11-19 20:27:18

标签: wcf enterprise-library

我实现了自定义异常处理程序,除了来自xml配置策略的映射外。这些映射适用于标准In [18]: c = a/b; c Out[18]: x/3 - 1/3 In [19]: d = c.factor(); d Out[19]: (x - 1)/3 In [20]: print(latex(d)) \frac{1}{3} \left(x - 1\right)

我的实施

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler

和部分配置

[ConfigurationElementType(typeof(CustomHandlerData))]
    public class IdentityFaultContractExceptionHandler : IExceptionHandler
    {
        public IdentityFaultContractExceptionHandler(NameValueCollection attributes)
        {
        }

        public IdentityFaultContractExceptionHandler(Type faultContractType, NameValueCollection attributes)
        {
        }

        public IdentityFaultContractExceptionHandler(Type faultContractType, string exceptionMessage, NameValueCollection attributes)
        {
        }

        public IdentityFaultContractExceptionHandler(IStringResolver exceptionMessageResolver, Type faultContractType, NameValueCollection attributes)
        {
        }

        public Exception HandleException(Exception exception, Guid handlingInstanceId)
        {
            return new Exception();
        }

当我删除<add name="All Exceptions" type="System.Exception, mscorlib" postHandlingAction="ThrowNewException"> <exceptionHandlers> <add type="MyClass.IdentityFaultContractExceptionHandler, MyClass" exceptionMessage="An error occurred in the service." faultContractType="MyClass.UnexpectedServerFault, MyClass" name="Fault Contract Exception Handler" > <mappings> <add source="{Message}" name="Message" /> </mappings> </add> </exceptionHandlers> </add> 节点服务时,当我添加时,我收到错误:无法识别元素mappping

1 个答案:

答案 0 :(得分:1)

如果您使用的是CustomHandlerData属性,那么您的配置需要使用XML属性,然后将其作为NameValueCollection传递给自定义处理程序构造函数。如果您想拥有自定义XML,则必须使用Full Design-time Integration。如果你想走这条路,那么你应该查看FaultContractExceptionHandlerData源代码,因为你的代码可能非常相似。