Special string character deletion does not work. c#

Asked

Viewed 83 times

0

I have this string:

EM RECUPERA�?�?O

This string comes to me in a XML and I use the following code to treat that:

byte[] bytes = Encoding.Default.GetBytes(xmlRetorno);
xmlRetorno = Encoding.UTF8.GetString(bytes);

But it’s 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;
    }
  • 1

    what code retrieves this XML? it seems to me that the error is before and not at this time. If you can put the code in the question !

  • 1

    Inside XML is with normal characters or with this �?? It is better you add in question the way you download this file, possibly the problem is in the download and not in the way to open, as it happens in that question

  • I tested it in Soap UI and the xml comes like this...

  • @Newbie as you make the rescue code of xml?

  • @newcomer I believe that the .ToString is occurring this. take the return of XML in a var and use a method that redeems the XML, in my case in sending and return XML I use schemas to serialize and say the same with patterns unicode and encoding. Do it just for testing.

  • @newbie is think it’s coding Webservice, maybe it’s another coding has to research it.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.