I have this string
:
EM RECUPERA�?�?O
This string comes in a XML
and I use the following code to handle this:
byte[] bytes = Encoding.Default.GetBytes(xmlRetorno);
xmlRetorno = Encoding.UTF8.GetString(bytes);
But it is not working. It's still the same.
So I return the XML:
public string EnviarXmlSoap(string methodName, string body, string url)
{
WebRequest webRequest = WebRequest.Create(url);
HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add("SOAPAction: http://tempuri.org/" + methodName);
httpRequest.ProtocolVersion = HttpVersion.Version11;
httpRequest.Credentials = CredentialCache.DefaultCredentials;
Stream requestStream = httpRequest.GetRequestStream();
//Create Stream and Complete Request
StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.UTF8);
StringBuilder soapRequest = new StringBuilder("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
soapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
soapRequest.Append("xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:"+methodName+"\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"> <soapenv:Header/> <soapenv:Body>");
soapRequest.Append(body);
soapRequest.Append("</soapenv:Body></soapenv:Envelope>");
streamWriter.Write(soapRequest.ToString());
streamWriter.Close();
string xml = soapRequest.ToString();
//Get the Response
HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
StreamReader srd = new StreamReader(wr.GetResponseStream());
string resulXmlFromWebService = srd.ReadToEnd();
return resulXmlFromWebService;
}