/// <summary>
        /// Factory used to create the expected <see cref="MessageFault"/> to be used when returning this fault type.
        /// </summary>
        /// <param name="fault">The <see cref="ServiceUnavailableFault"/> to create a <see cref="MessageFault"/> from.</param>
        /// <returns>The appropriate <see cref="MessageFault"/> for the supplied <see cref="ServiceUnavailableFault"/>.</returns>
        public static MessageFault CreateStandardFault(ServiceUnavailableFault fault)
        {
            var faultCode   = CreateStandardCode();
            var faultReason = CreateStandardReason();

            return(MessageFault.CreateFault(faultCode, faultReason, fault));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Enables the creation of a custom <see cref="FaultException{T}"/> that is returned from an exception in the course of a service method.
 /// </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="Message"/> object that is returned to the client, or service, in the duplex case.</param>
 public virtual void ProvideFault(Exception error, MessageVersion version, ref Message fault)
 {
     if (error is ValidationException)
     {
         var validationException = error as ValidationException;
         var validationFault     = new MessageValidationFault(validationException.ValidationResult.ErrorMessage);
         fault = Message.CreateMessage(version, MessageValidationFault.CreateStandardFault(validationFault), Constants.Faults.MessageValidationFault.Action);
     }
     else if (error is XmlSchemaValidationException)
     {
         var validationException = error as XmlSchemaValidationException;
         var validationFault     = new MessageValidationFault(validationException.Message);
         fault = Message.CreateMessage(version, MessageValidationFault.CreateStandardFault(validationFault), Constants.Faults.MessageValidationFault.Action);
     }
     else if (error is TimeoutException)
     {
         var slaFault = new SlaViolationFault();
         slaFault.Descriptions.Add(new Description(error.Message, CultureInfo.CurrentCulture));
         fault = Message.CreateMessage(version, SlaViolationFault.CreateStandardFault(slaFault), Constants.Faults.SlaViolationFault.Action);
     }
     else if (error is FaultException)
     {
         // Allow through
     }
     else
     {
         var serviceUnavailableFault = new ServiceUnavailableFault();
         fault = Message.CreateMessage(version, ServiceUnavailableFault.CreateStandardFault(serviceUnavailableFault), Constants.Faults.ServiceUnavailableFault.Action);
     }
 }