在 C# Web 服务中处理 UTF-8 字符串
我使用 C# 工具 wsdl.exe 创建了一个简单的 Web 服务客户端。除了一件事之外,它工作得很好。响应中返回的 UTF-8 字符串似乎已转换为 ASCII。使用 SOAPUI,我可以看到 Web 服务返回正常的 UTF-8 编码字符串。但是当我调试收到的响应时,UTF-8 内容似乎已经转换为 ASCII 并且完全是乱码。在我应该看到包含日语字符的字符串的地方,我看到了“?”列表。
- 有没有办法将字符串转换回 Unicode,以便在调试器中看到原始响应字符串?
- 有没有办法防止服务响应中的字符串出现乱码?
I created a simple web service client using the C# tool wsdl.exe. It works fine except for one thing. It seems that UTF-8 strings returned in response are converted to ASCII. Using SOAPUI I can see normal UTF-8 encoded strings being returned by the web service. But when I debug the response I received the UTF-8 content seems to have already been converted to ASCII and is completely garbled. Where I should see a string containing Japanese characters I'm seeing a list of '?'.
- Is there a way to convert back the string to Unicode so that seen in the debugger is the original response string ?
- Is there a way to prevent the string from getting garbled in the service response?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您实际上按照 @Sam 提供的文档对字符串进行编码:
Ensure you are actually encoding the strings as per the documentation @Sam provided:
不要以字符串形式发送数据,而是尝试以字节数组形式发送数据,并在客户端将其转换为相同的编码。
Instead of sending the data as a string, try sending the data as a byte array and convert it to the same encoding on the client side.