【发布时间】:2012-01-18 07:17:45
【问题描述】:
我有一个配置了 Enterprise Library 5“记录应用程序块”、“验证应用程序块与 WCF 集成”和“异常处理应用程序块 WCF 提供程序”的 WCF 服务,并使用如下流式 API 对其进行配置:
builder.ConfigureExceptionHandling()
// -----------------------------------------------------
// Preventing Enterprise Library Validation Block exceptions from getting shielded.
// -----------------------------------------------------
.GivenPolicyWithName("WCF Exception Shielding")
.ForExceptionType<FaultException<ValidationFault>>()
.ThenDoNothing()
// -----------------------------------------------------
// Shielding unhandled exceptions
// -----------------------------------------------------
.ForExceptionType<Exception>()
.LogToCategory("My Logging Category")
.WithSeverity(TraceEventType.Critical)
.ShieldExceptionForWcf(typeof(ServiceUnhandledFault), Resources.UnhandledException_ErrorMessage)
.ThenThrowNewException();
服务实现:
[ServiceContract]
[ValidationBehavior]
[ExceptionShielding("WCF Exception Shielding")]
public interface IMyService
{
[OperationContract]
[FaultContract(typeof(ValidationFault))]
[FaultContract(typeof(ServiceUnhandledFault))]
void InsertEntity(MyEntity file);
}
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
public partial class MyService : IMyService { ...Implementation... }
如果我将服务调试行为的“IncludeExceptionDetailInFaults”属性设置为 false,并使用无法正确验证的实体调用服务操作,服务中将引发以下异常:
Microsoft.Practices.Unity.ResolutionFailedException:依赖项解析失败,类型 =“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl”,名称 =“WCF 异常屏蔽”。 异常发生时:解决时。 例外是:InvalidOperationException - ExceptionPolicyImpl 类型有多个长度为 2 的构造函数。无法消除歧义。
但如果我将 IncludeExceptionDetailInFaults 设置为 true,则会将验证错误返回给客户端。
有人知道我错过了什么吗?
【问题讨论】: