While I was working on web services consumption, there was a issue in web services that if I send any wrong request xml, web service server send a web exception "
(500) Internal Server Error." But the actual response xml was not catched through it.
For catching this I was using HTTP Debugger Pro. But HTTP Debugger has one drawback that we cannot use it in release version (It is used only for developement server.) :(
Then I try to catch this issue at the programming logic.
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUrl); req.Method = "POST"; req.ContentLength = request.Length; req.ContentType = "text/xml;charset=\"utf-8\""; req.Accept = "text/xml"; req.Headers.Add("SOAPAction", headerUrl); req.KeepAlive = false; Stream str = req.GetRequestStream(); StreamWriter writer = new StreamWriter(str); writer.Write(request); writer.Flush(); Stream resp = Stream.Null; WebResponse response = null; try { response = req.GetResponse(); resp = response.GetResponseStream(); } catch (WebException ex) { HttpWebResponse errResp = ex.Response as HttpWebResponse; if (errResp == null) { throw new WebException("Response was null"); } using (StreamReader reader = new StreamReader(errResp.GetResponseStream())) { string error = reader.ReadToEnd();
throw new WebException(ex.Message + "Error response XML: " + error); } }
And Guys it works :)