0

When the wrong answer(500) comes from Soap Web Services, i want to see the error details. I can use soap tool, i can do this process using a soap tool and see the error details. But using the WebResponse class in c#, i cannot see the error details.

Do you have any information on this subject?

Soap UI Tool Response Header Raw soap tool response header raw soap tool error detail

WebResponse Exception enter image description here

Regards.

ibaris
  • 146
  • 2
  • 10
  • Is this for troubleshooting, or do you need to get that information into an error message for the user or log entry? If for troubleshooting you can [enable diagnostic tracing](https://stackoverflow.com/questions/4271517/how-to-turn-on-wcf-tracing) – Crowcoder Dec 21 '20 at 13:42
  • I need an error message for the users – ibaris Dec 22 '20 at 05:22

1 Answers1

1

Finally I have reached the right conclusion. And, I wanted to share thinking that someone might need it.

catch (WebException ex)
{
    string exMessage = ex.Message;

    if (ex.Response != null)
    {
        using (var responseReader = new StreamReader(ex.Response.GetResponseStream()))
        {
            exMessage = responseReader.ReadToEnd();
        }
    }
}

Err Details:

err_details

I wish a healthy New Year for all of us!

ibaris
  • 146
  • 2
  • 10
  • Still didn't get the proper message (getting Unicode characters). request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; – Hassan Rahman Jul 23 '23 at 20:28