views:

38

answers:

1

I have a routine that submits a SOAP request using HttpWebRequest and WebResponse. If the SOAP Request fails the server sends back HTTP/1.1 500 Internal Server Error. When I trap the error I have yet to find a way to view the body of the reply which contains the fault code.

Is there a way to retrieve the message body when the server returns a 500 internal Server Error?

In body of the reply which I am not able to retrieve.

faultstring xml:lang="en-US" Specified argument was out of the range of valid values.

A: 

I haven't time to test this, but a WebException will be thrown in this situation.

You can get access to the error response via the WebException.Response property.

You will then be able to access information from the respons, e.g. you could try calling WebException.Response.GetResponseStream() to get the body of the response.

Joe
Yes this works. catch (WebException e) { System.IO.StreamReader reader = new System.IO.StreamReader(e.Response.GetResponseStream()); string str = reader.ReadToEnd();
twamn
Note that in some cases, `Response` will be null.
Brian