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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:43:52+00:00 2026-06-03T16:43:52+00:00

From my understanding the following should properly throw a custom error from a WCF

  • 0

From my understanding the following should properly throw a custom error from a WCF Rest service:

[DataContract(Namespace = "")]
public class ErrorHandler
{
    [DataMember]
    public int errorCode { get; set; }

    [DataMember]
    public string errorMessage { get; set; }
} // End of ErrorHandler

public class Implementation : ISomeInterface
{
    public string SomeMethod()
    {
        throw new WebFaultException<ErrorHandler>(new ErrorHandler()
        {
            errorCode = 5,
            errorMessage = "Something failed"
        }, System.Net.HttpStatusCode.BadRequest);
    }
}

In Fiddler this seems to work, I get the following raw data:

HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Length: 145
Content-Type: application/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Set-Cookie: ASP.NET_SessionId=gwsy212sbjfxdfzslgyrmli1; path=/; HttpOnly
X-Powered-By: ASP.NET
Date: Thu, 03 May 2012 17:49:14 GMT

<ErrorHandler xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><errorCode>5</errorCode><errorMessage>Something failed</errorMessage></ErrorHandler>

But now on my client side I have the following code:

WebChannelFactory<ISomeInterface> client = new WebChannelFactory<ISomeInterface>(new Uri(targetHost));

ISomeInterface someInterface = client.CreateChannel();
try
{
  var result = someInterface.SomeMethod();
}
catch(Exception ex)
{
   // Try to examine the ErrorHandler to get additional details.
}

Now when the code runs, it hits the catch and is a System.ServiceModel.ProtocolException with the message ‘The remote server returned an unexpected response: (400) Bad Request.’. It seems that I have no way to see the ErrorHandler details at this point. Has anyone run into this? Is there a way I can get the ErrorHander details at this point?

  • 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-03T16:43:55+00:00Added an answer on June 3, 2026 at 4:43 pm

    WebChannelFactory or ChannelFactory will only disclose to you the generic CommunicationException. You will need to use a IClientMessageInspector behavior or rely on WebRequest to return the actual error.

    For the IClientMessageInspector approach – see the comments in this blog entry.

    For the WebRequest approach, you can you the following to catch the WebException.

    try { }
    catch (Exception ex)
    {
        if (ex.GetType().IsAssignableFrom(typeof(WebException)))
        {
            WebException webEx = ex as WebException;
            if (webEx.Status == WebExceptionStatus.ProtocolError)
            {
                using (StreamReader exResponseReader = new StreamReader(webEx.Response.GetResponseStream()))
                {
                    string exceptionMessage = exResponseReader.ReadToEnd();
                    Trace.TraceInformation("Internal Error: {0}", exceptionMessage);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From my understanding of the docs this general approach should work: begin try1 rescue
MariaDB 5.3 introduced dynamic columns. From my understanding the next version of mysql should
I have some trouble understanding the output from the following code: int main(void) {
Basically I'm trying to upgrade my application, and to my understanding the following should
From my understanding, const modifiers should be read from right to left. From that,
I have the following class: class Tileset { //base class public: static std::vector<Tileset*> list;
From my understanding, helpers are mainly used to clean up views from some view-specific
From my understanding the XMPP protocol is based on an always-on connection where you
From my understanding of the CSS spec, a table above or below a paragraph
From my understanding, Lua is an embeddable scripting language that can execute methods on

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.