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 8676081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:05:59+00:00 2026-06-12T20:05:59+00:00

I have an application that uses a ClientBase object generated by a service reference

  • 0

I have an application that uses a ClientBase object generated by a service reference to call a third party WCF SOAP service. Every once in awhile, the service call returns a fault exception instead with an exception message of “An error occurred while processing the request” which is completely generic.

Even during service errors, there is supposed to be a trace ID value that comes back with the response so the developers of that service can debug/troubleshoot any issues. So, what I ideally want is to log the raw response that comes back to my ClientBase object when there is an exception. I don’t want to log every single message if possible, that would be overkill IMO.

Is there a way to capture that using the ClientBase? Maybe there’s some context object that contains the raw response content? This needs to be built into my application if possible. I know there are tools out there that act as a proxy between the client and service that can log http requests/responses but that is not what I’m after.

  • 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-12T20:06:00+00:00Added an answer on June 12, 2026 at 8:06 pm

    At the ClientBase itself there’s no place where you can get that information. But you can add a custom message inspector at the client (IClientMessageInspector) where you can see all the messages that are being received; for those messages you can check the IsFault property, and if true log the message as you want.

    Update: Adding sample code

    using System.ServiceModel.Channels;
    using System.ServiceModel.Dispatcher;
    
    public class StackOverflow_12842014
    {
        [ServiceContract]
        public interface ITest
        {
            [OperationContract]
            string Echo(string text);
        }
        public class Service : ITest
        {
            public string Echo(string text)
            {
                if (text == "throw") throw new ArgumentException("Throwing as requested");
                return text;
            }
        }
        class MyClient : ClientBase<ITest>, ITest
        {
            public MyClient(Binding binding, EndpointAddress address)
                : base(binding, address)
            {
                this.Endpoint.Behaviors.Add(new MyFaultLogger());
            }
    
            public string Echo(string text)
            {
                return this.Channel.Echo(text);
            }
    
            class MyFaultLogger : IEndpointBehavior, IClientMessageInspector
            {
                public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
                {
                }
    
                public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
                {
                    clientRuntime.MessageInspectors.Add(this);
                }
    
                public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
                {
                }
    
                public void Validate(ServiceEndpoint endpoint)
                {
                }
    
                public void AfterReceiveReply(ref Message reply, object correlationState)
                {
                    if (reply.IsFault)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Fault received!: {0}", reply);
                        Console.ResetColor();
                    }
                }
    
                public object BeforeSendRequest(ref Message request, IClientChannel channel)
                {
                    return null;
                }
            }
        }
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            host.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
            host.AddServiceEndpoint(typeof(ITest), new BasicHttpBinding(), "");
            host.Open();
            Console.WriteLine("Host opened");
    
            MyClient client = new MyClient(new BasicHttpBinding(), new EndpointAddress(baseAddress));
    
            Console.WriteLine(client.Echo("Hello"));
            try
            {
                Console.WriteLine(client.Echo("throw"));
            }
            catch (Exception)
            {
                Console.WriteLine("The fault should have been traced");
            }
    
            client.Close();
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have client application that uses WCF service to insert some data to backend
I have an application that uses a third party native C dll. Everything works
I have an application that uses Hibernate. It generated the following SQL statement. I
We have an application that uses Lucene.NET within a windows service to reindex our
I have an application that uses WCF for all DataAccess. It returns some business
I have an application that uses a local ip-adress to connect to a soap
I have an application that uses the APNS Feedback Service to detect when a
I have an application that uses the mmap system call, I was having an
I have an application that uses a ResourceDictionary to set the styles, which it
I have an application that uses multiple WebViews. Nowhere do I set the priority

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.