A
Anbu
Hi All,
How to Receive Soap Exception using HTTP POST operation.
Here is the code that calls the Web Service
try
{
string strg = envelope.InnerXml;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(destination);
req.Method = "POST";
req.KeepAlive = true;
req.ContentType = "text/xml";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(strg);
req.ContentLength = bytes.Length;
req.Headers.Add("SOAPAction: " + SoapAction);
System.IO.Stream st = req.GetRequestStream();
st.Write(bytes, 0, bytes.Length);
st.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
System.IO.Stream st1 = res.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(st1,
System.Text.Encoding.UTF8);
string txt = sr.ReadToEnd();
SoapEnvelope response = new SoapEnvelope();
response.LoadXml(txt);
//this.txtSOAPResponse.Text = txt;
res.Close();
//Console.WriteLine(response.Envelope.OuterXml);
return response;
//return true;
}
catch (SoapException soapexp)
{
SoapEnvelope responseexp = new SoapEnvelope();
responseexp.LoadXml(soapexp.Message);
return responseexp;
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
Console.WriteLine(exp.StackTrace);
SoapEnvelope responseexp = new SoapEnvelope();
responseexp.LoadXml(exp.Message);
return responseexp;
}
Using above method does not return the SoapFault or SoapException. How
can I capture the SoapException thrown by the web service?
TIA
How to Receive Soap Exception using HTTP POST operation.
Here is the code that calls the Web Service
try
{
string strg = envelope.InnerXml;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(destination);
req.Method = "POST";
req.KeepAlive = true;
req.ContentType = "text/xml";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(strg);
req.ContentLength = bytes.Length;
req.Headers.Add("SOAPAction: " + SoapAction);
System.IO.Stream st = req.GetRequestStream();
st.Write(bytes, 0, bytes.Length);
st.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
System.IO.Stream st1 = res.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(st1,
System.Text.Encoding.UTF8);
string txt = sr.ReadToEnd();
SoapEnvelope response = new SoapEnvelope();
response.LoadXml(txt);
//this.txtSOAPResponse.Text = txt;
res.Close();
//Console.WriteLine(response.Envelope.OuterXml);
return response;
//return true;
}
catch (SoapException soapexp)
{
SoapEnvelope responseexp = new SoapEnvelope();
responseexp.LoadXml(soapexp.Message);
return responseexp;
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
Console.WriteLine(exp.StackTrace);
SoapEnvelope responseexp = new SoapEnvelope();
responseexp.LoadXml(exp.Message);
return responseexp;
}
Using above method does not return the SoapFault or SoapException. How
can I capture the SoapException thrown by the web service?
TIA