Hi,
Im testing a web service from my windows app in C#. I create a soap body and
pass to the HttpWebRequest and then get the response as below.
private void TestService()
{
string quotes = "\"";
// Set the uri to send the request to
string requestUri =
"http://localhost/TestServices/TestService.asmx/RetrieveTest";
string SoapEnv;
SoapEnv = "<soap:Envelope xmlns:xsi=" + quotes
+ "http://www.w3.org/2001/XMLSchema-instance" + quotes +
" xmlns:xsd=" + quotes +
"http://www.w3.org/2001/XMLSchema" + quotes +
" xmlns:soap=" + quotes +
"http://schemas.xmlsoap.org/soap/envelope/" + quotes
+ ">" +
" <soap:Body>" +
"<RetrieveTest xmlns=" + quotes +
"http://localhost/TestServices" + quotes + ">" +
"<TestID>string</TestxID>" +
" </RetrieveTest>" +
" </soap:Body>" +
" </soap:Envelope>";
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create(requestUri);
if (myRequest != null)
{
myRequest.Method = "POST";
myRequest.ContentLength = SoapEnv.Length;
myRequest.ContentType = "text/xml; charset=utf-8";
}
StreamWriter myWriter = new StreamWriter(myRequest.GetRequestStream());
myWriter.Write(SoapEnv);
myWriter.Close();
//I get the response here
try
{
//Get an error in GetResponse() here
HttpWebResponse myHttpWebResponse = (HttpWebResponse)
myRequest.GetResponse();
StreamReader myStreamReader = new StreamReader
(myHttpWebResponse.GetResponseStream());
string strResponse = myStreamReader.ReadToEnd();
myStreamReader.Close();
}
catch (WebException exc)
{
//Get an exception here i.e.
"The remote server returned an error: (500) Internal Server Error"
The Status shows "ProtocolError"
}
}
The catch is done when GetResponse() is called. Will appreciate any
suggestions/help on the above.
Thanks.