Read this article in your language IT | EN | DE | ES
Every time you access or consume a service or resource which is outside your control you should always place in an exception block. However you also want to record the request and response, or maybe dissect the response. In my case a custom exception from an Apache box, running Java soap.
1: catch (System.Net.WebException ex)
2: {
3: string packet = "";
4: using (Stream StreamObj = ((HttpWebResponse)ex.Response).GetResponseStream())
5: {
6: using (StreamReader sr = new StreamReader(StreamObj, Encoding.UTF8))
7: {
8: packet = sr.ReadToEnd();
9: }
10: }
11: Console.Write(packet);
12: Console.ReadLine();
13: }
This will drop out the response packet, from the exception
you won’t get the full detail, you need to prompt the CLR to
dig deeper into the WebException object.