上一篇简单介绍了配置应用程序使客户端获取WCF抛出的SOAP异常,但是这些SOAP异常信息只包含InnerException ,Message,StackTrace,但是在实际情况中,我们
可能需要提供更详细的信息,在WCF中可以发送给客户端未声明的和声明的两种类型的SOAP错误,上一篇文章实际上是使用了未声明的SOAP错误。
本篇在上一篇的基础上演示通过WCF提供的FaultContractAttribute声明服务操作中的错误:
1.自定义一个用于错误契约的自定义类型
[DataContract]
public class DataAccessFault
{
[DataMember]
public string ExceptionMessage { get; set; }
[DataMember]
public string ExceptionCode { get; set; }
}