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

  • Home
  • SEARCH
  • 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 3286122
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:20:40+00:00 2026-05-17T20:20:40+00:00

I have a server which is throwing WebFaultException try { … } catch (InvalidPasswordException)

  • 0

I have a server which is throwing WebFaultException

try
{
    ...
}
catch (InvalidPasswordException)
{

    throw new WebFaultException<String>
                   ("This is a bad password", 
                    HttpStatusCode.Unauthorized);
}

So far so good. However when this WebFault is caught in another C# project (the client) I don’t know how to get the details.

try
{
    HttpWebRequest httpWebRequest = WebRequest.Create(uri) as HttpWebRequest;

    httpWebRequest.Method = verb;
    httpWebRequest.ContentType = "text/xml";
    httpWebRequest.ContentLength = serializedPayload.Length;

    using (StreamWriter streamOut = new StreamWriter(httpWebRequest.GetRequestStream(), Encoding.ASCII))
    {
        streamOut.Write(serializedPayload);
        streamOut.Close();
    }

    // error here on GetResponseStream
    using (StreamReader streamIn = new StreamReader(httpWebRequest.GetResponse().GetResponseStream()))
    {
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
            return strResponse;
    }
}
catch (Exception e)
{
   // The exception is of type WebException with unauthorized but don't know where the details are
}

This code catches a WebException which I can’t find the details for, just the unauthorized.

Thanks

UPDATE 1: When I do the request in fiddler the response body is the detail but as that exception is thrown before the response body is ever read then it isn’t showing up. So the question is how do I read the response body DESPITE a non 200 being thrown.

Fiddler Raw Response:

HTTP/1.1 401 Unauthorized
Server: ASP.NET Development Server/10.0.0.0
Date: Tue, 12 Oct 2010 22:42:31 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 100
Cache-Control: private
Content-Type: application/xml; charset=utf-8
Connection: Close

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Email/Password Mismatch</string>
  • 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-05-17T20:20:40+00:00Added an answer on May 17, 2026 at 8:20 pm

    I’m just guessing, but I think you just need to check the .StatusCode member of the result of GetResponse() and don’t try to call GetResponseStream() unless it’s 200. If it’s an error code (401 in your case), then the error details should be in the .Content member of GetResponse().

    Something like:

    var r = httpWebRequest.GetResponse();
    if(r.StatusCode != 200)
    {
        MessageBox.Show(r.Content); // Display the error 
    }
    else
    {
        var streamIn = new StreamReader(r.GetResponseStream());
        string strResponse = streamIn.ReadToEnd();
        streamIn.Close();
        return strResponse;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have this scenario: A server which contains needed data and client component which
I have an HTTP server which is in our internal network and accessible only
I have a web server which saves cache files and keeps them for 7
I have an x64 server which, since my libraries are compiled to AnyCPU, run
We have a reporting server which has a bunch of reports and some ad
I have a slapd LDAP server which is critical to my application. I want
I have client and server programs which now communicate via TCP. I'm trying out
I have a file on a Windows 2003 server which is locked by a
I have a list of strings on my server which I am trying to
Is that possible to have a single PHP SOAP server which will handle requests

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.