/// <summary> /// Provide a fault. The Message fault parameter can be replaced, or set to null to suppress reporting a fault. /// </summary> /// <param name="error">The <see cref="Exception"/> object thrown in the course of the service operation.</param> /// <param name="version">The SOAP version of the message.</param> /// <param name="fault">The <see cref="System.ServiceModel.Channels.Message"/> object that is returned to the client, or service, in the duplex case.</param> public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { BusinessRuleFaultExceptionType f = new BusinessRuleFaultExceptionType { Code = -100, Reason = "xxx" }; // create a fault message containing our FaultContract object FaultException <BusinessRuleFaultExceptionType> faultException = new FaultException <BusinessRuleFaultExceptionType>(f, error.Message); MessageFault faultMessage = faultException.CreateMessageFault(); var msgFault = new XmlSerializerMessageFault(faultMessage.Code, faultMessage.Reason, f); fault = Message.CreateMessage(version, msgFault, faultException.Action); }
/// <summary> /// Provide a fault. The Message fault parameter can be replaced, or set to null to suppress reporting a fault. /// </summary> /// <param name="error">The <see cref="Exception"/> object thrown in the course of the service operation.</param> /// <param name="version">The SOAP version of the message.</param> /// <param name="fault">The <see cref="System.ServiceModel.Channels.Message"/> object that is returned to the client, or service, in the duplex case.</param> public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { //If it's a FaultException already, then we have nothing to do if (error is FaultException) { return; } error = MyExceptionHandler.HandleError(error); var serviceDebug = OperationContext.Current.EndpointDispatcher.ChannelDispatcher.IncludeExceptionDetailInFaults; BusinessRuleFaultExceptionType f = new BusinessRuleFaultExceptionType { Code = -100, Reason = "xxx" }; FaultException <BusinessRuleFaultExceptionType> faultException = new FaultException <BusinessRuleFaultExceptionType>(f, error.Message); MessageFault faultMessage = faultException.CreateMessageFault(); fault = Message.CreateMessage(version, faultMessage, faultException.Action); }