我使用C#工具wsdl.exe创建了一个简单的web服务客户机。除了一件事外,一切都很好。响应返回的UTF-8字符串似乎被转换为ASCII。使用SOAPUI,我可以看到web服务返回普通的UTF-8编码字符串。但是当我调试响应时,我收到的UTF-8内容似乎已经被转换成ASCII,并且完全被混淆了。在哪里我应该看到一个包含日语字符的字符串,我看到的是'?‘的列表。
发布于 2011-05-26 07:09:19
确保您实际上正在按照所提供的文档@Sam对字符串进行编码:
using System;
using System.Text;
class UTF8EncodingExample {
public static void Main() {
// Create a UTF-8 encoding.
UTF8Encoding utf8 = new UTF8Encoding();
// A Unicode string with two characters outside an 8-bit code range.
String unicodeString =
"This unicode string contains two characters " +
"with codes outside an 8-bit code range, " +
"Pi (\u03a0) and Sigma (\u03a3).";
Console.WriteLine("Original string:");
Console.WriteLine(unicodeString);
// Encode the string.
Byte[] encodedBytes = utf8.GetBytes(unicodeString);
Console.WriteLine();
Console.WriteLine("Encoded bytes:");
foreach (Byte b in encodedBytes) {
Console.Write("[{0}]", b);
}
Console.WriteLine();
// Decode bytes back to string.
// Notice Pi and Sigma characters are still present.
String decodedString = utf8.GetString(encodedBytes);
Console.WriteLine();
Console.WriteLine("Decoded bytes:");
Console.WriteLine(decodedString);
}
}发布于 2011-08-07 10:16:59
不要将数据作为字符串发送,而是尝试将数据作为字节数组发送,并在客户端将其转换为相同的编码。
https://stackoverflow.com/questions/3913177
复制相似问题