Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8805295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:49:48+00:00 2026-06-14T01:49:48+00:00

When creating a generic fault exception FaultException<MyWebServiceFaultDetail> and passing it back to the message

  • 0

When creating a generic fault exception FaultException<MyWebServiceFaultDetail> and passing it back to the message inspector pipeline as a MessageFault, the client will not receive the generic fault in its catch (FaultException<MyWebServiceFaultDetail> ex) block, it is only caught within the catch (FaultException ex) block.

The MyWebServiceFaultDetail and IClientMessageInspector implication both live within the same project as the client WCF web reference in a single project MyProjects.MyWebService.

The WebService is called by another project which has a reference to the MyProjects.MyWebService project.

*Comments have been removed for brevity

The data contract:

[DataContract]
public class MyWebServiceFaultDetail
{
    [DataMember]
    public string MessageDetail { get; set; }

    [DataMember]
    public string MessageType { get; set; }

    [DataMember]
    public string TransactionComplete { get; set; }

    [DataMember]
    public string TransactionSuccess { get; set; }

    public override string ToString()
    {
        return string.Format("Detail[MessageDetail={0}] [MessageType={1}] [TransactionComplete={2}] [TransactionSuccess={3}]", MessageDetail,MessageType ,TransactionComplete ,TransactionSuccess );
    }
}

The message inspector. I would just add that reply.Headers.Action is null when this method runs. Setting the action value on the call to CreateMessage() has had no affect. Values I have tried.

.CreateMessage(reply.Version, ex.CreateMessageFault(), “*”);

.CreateMessage(reply.Version, ex.CreateMessageFault(), reply.Headers.Action);

.CreateMessage(reply.Version, ex.CreateMessageFault(), ex.Action);

internal class ResponseMessageInspector : System.ServiceModel.Dispatcher.IClientMessageInspector
{
    private static NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();

    public void AfterReceiveReply(ref Message reply, object correlationState)
    {
        MessageBuffer bufferedMessage = null;

        try
        {
            bufferedMessage = reply.CreateBufferedCopy(Int32.MaxValue);

            Message replacedMessage = bufferedMessage.CreateMessage();

            if (bufferedMessage.MessageContentType != "application/soap+msbin1" || reply.IsEmpty || reply.IsFault)
            {
                reply = replacedMessage;
                return;
            }

            bool isErrorMessage;

            var messageReader = replacedMessage.GetReaderAtBodyContents();

            isErrorMessage = (messageReader.Name == "TransactionReport");

            if (isErrorMessage)
            {
                string transactionComplete = "",
                    transactionSuccess = "",
                    messageType = "",
                    messageDetail = "",
                    messageBrief = "";

                while (messageReader.Read())
                {
                    if (messageReader.NodeType == XmlNodeType.Element && !messageReader.IsEmptyElement)
                    {
                        switch (messageReader.Name)
                        {
                            case "TransactionComplete":
                                transactionComplete = messageReader.ReadString();
                                break;

                            case "TransactionSuccess":
                                transactionSuccess = messageReader.ReadString();
                                break;

                            case "MessageType":
                                messageType = messageReader.ReadString();
                                break;

                            case "MessageDetail":
                                messageDetail = messageReader.ReadString();
                                break;

                            case "MessageBrief":
                                messageBrief = messageReader.ReadString();
                                break;

                            default:
                                break;
                        }
                    }
                }

                if (string.IsNullOrEmpty(messageBrief))
                {
                    messageBrief = "My response processing fault: {Unable to obtain error message from My response, enable WCF message tracing for more detailed information}";

                    _logger.Warn(messageBrief);
                }

                FaultException ex = new FaultException<MyWebServiceFaultDetail>(
                    new MyWebServiceFaultDetail
                    {
                        TransactionComplete = transactionComplete,
                        TransactionSuccess = transactionSuccess,
                        MessageDetail = messageDetail,
                        MessageType = messageType
                    },
                    new FaultReason(messageBrief));

                Message faultMessage = Message.CreateMessage(reply.Version, ex.CreateMessageFault(), null);

                faultMessage.Headers.CopyHeadersFrom(reply.Headers);
                faultMessage.Properties.CopyProperties(reply.Properties);

                reply = faultMessage;
            }
            else
                reply = bufferedMessage.CreateMessage();
        }
        finally
        {
            if (bufferedMessage != null)
                bufferedMessage.Close();
        }
    }

    public object BeforeSendRequest(ref Message request, System.ServiceModel.IClientChannel channel)
    {
        return null;
    }
}

The client code that is reciving the FaultException but not a FaultException<MyWebServiceFaultDetail>

 internal static T TrySendToMyWebService<T>(
        CallWebServiceDelegate<T> callWebService,
        bool expectResponce,
        out MessageProcessorResult result) where T : class
    {
        T MyWebServiceResponce = null;

        result = new MessageProcessorResult();

        using (ServiceRequestConnectorServiceSoapClient ws =
          new ServiceRequestConnectorServiceSoapClient())
        {
            try
            {
                MyWebServiceWebServiceHelper.LogOn(ws);
                MyWebServiceResponce = callWebService(ws);
                if (expectResponce && MyWebServiceResponce == null)
                {
                    result.ShouldRetry = true;
                    result.RetryReason = "Unexpected MyWebService web service response. The response was null";
                }
            }
            catch (FaultException<MyWebServiceFaultDetail> ex)
            {
                // I never get called :(
                result.Exception = ex;
                result.ShouldRetry = true;
                result.RetryReason = string.Format("An Exception was raised calling the MyWebService web service: Reason:{0}  /r/nDetails: {1}", ex.Reason, ex.Detail.ToString());
                _logger.ErrorException(result.RetryReason, ex);
            }
            catch (FaultException ex)
            {
                result.Exception = ex;
                result.ShouldRetry = true;
                result.RetryReason = string.Format("An Exception was raised calling the MyWebService web service: {0}", ex.Message);
                _logger.ErrorException(ex.Message, ex);
            }
            finally
            {
                MyWebServiceWebServiceHelper.LogOff(ws);
            }
        }

        return MyWebServiceResponce;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:49:49+00:00Added an answer on June 14, 2026 at 1:49 am

    Just throw the new typed FaultException<MyWebServiceFaultDetail> from the AfterReceiveReply of your message inspector.

    FaultException ex = new FaultException<MyWebServiceFaultDetail>(
                    new MyWebServiceFaultDetail
                    {
                        TransactionComplete = transactionComplete,
                        TransactionSuccess = transactionSuccess,
                        MessageDetail = messageDetail,
                        MessageType = messageType
                    },
                    new FaultReason(messageBrief));
    throw ex;
    

    If your detail class is declared on the client side, you don’t even need to decorate it with DataContract attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not really familiar with creating generic methods, so I thought I'd put this
I'm creating generic DAO for my DataNucleus JDO DAOs. Generic DAO will do get,
I am creating a generic app which will have different builds for different customers.
I'm thinking of creating a generic message queue to handle various inter-process messages. (WCF
I'm creating 'generic' wrapper above SQL procedures, and I can resolve all required parameters'
Suppose we are creating a generic control in .NET. E.g. a tree. I don't
I am looking into creating type-safe generic controls. This is targeting the (reduced) generics
I'm creating instances of a generic type using reflection: public interface IModelBuilder<TModel> { TModel
I'm trying to register a factory method for creating instances of an open generic
after install hugs and then install ghc6 then install generic-haskell has the following message,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.