WCF Receive UTF-8 Response

4

I'm consuming a third party Webservice through a Console application .

I get an object as a return, and on this object I need to read an attribute called ReturnMessage .

However, the text is unconfigured, so it looks like this " The Security Code sent is Invalid ." To fix the problem, I created a method that formats the string passed to UTF-8 , follow the code below.

 byte[] bytes = Encoding.Default.GetBytes(texto);
 string textoFormatado = Encoding.UTF8.GetString(bytes);   
 return textoFormatado;

After formatted the message is as follows " The Security Code Sent is Invalid "

My question is, is there any way I can get this return on UTF-8 without having to do this conversion?

I figured I could parameterize something in app.config as I did below, but it did not work.

Does anyone have any idea if this is possible?

    
asked by anonymous 25.11.2016 / 12:41

1 answer

0

Try this from here:

Encoding iso = Encoding.GetEncoding("ISO-8859-1");
Encoding utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(Message);
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
string msg = iso.GetString(isoBytes);

Reference: link

    
25.11.2016 / 12:58