500 error consuming WebService [closed]

2

The code is returning the following error message:

  An unhandled exception of type 'System.Net.WebException' occurred in System.dll

     

Additional information: The remote server returned an error: (500) Internal Server Error.

Does anyone know the reason for this problem?

 private void button1_Click(object sender, EventArgs e)
        {
            string xmlMessage = "<?xml version=\"1.0\" encoding=\"utf - 8\"?> " +
           @"< soap12:Envelope xmlns:xsi = ""http://www.w3.org/2001/XMLSchema-instanc"" xmlns: xsd = ""http://www.w3.org/2001/XMLSchema"" xmlns: soap12 = ""http://www.w3.org/2003/05/soap-envelope"" >"+
            @"< soap12:Body > <GetCurrencyByCountry xmlns = ""http://www.webserviceX.NET"" > < CountryName > Brazil </ CountryName >"+
            "</ GetCurrencyByCountry > </ soap12:Body ></ soap12:Envelope > ";

            string url = "http://www.webservicex.net/country.asmx?op=GetCurrencyByCountry";

            System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);


            byte[] requestInFormOfBytes = System.Text.Encoding.ASCII.GetBytes(xmlMessage);
            request.Method = "POST";
            request.ContentType = "text/xml;charset=utf-8";
            request.ContentLength = requestInFormOfBytes.Length;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(requestInFormOfBytes, 0, requestInFormOfBytes.Length);
            requestStream.Close();


            System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
            StreamReader respStream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);
            string receivedResponse = respStream.ReadToEnd();

            MessageBox.Show(receivedResponse);
            respStream.Close();
            response.Close();

        }
    
asked by anonymous 27.10.2016 / 12:35

0 answers