c# - ASP.NET SOAP Webservice,异常中的编码问题
问题描述
这是我的问题,我尝试使用以下代码对我的 web 服务的响应进行编码。
public static string ConvertToUTF8(string Cadena)
{
string mensajeex = Cadena;
Encoding utf8 = Encoding.UTF8;
Encoding unicode = Encoding.Unicode;
// Convert the string into a byte array.
byte[] unicodeBytes = unicode.GetBytes(mensajeex);
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, utf8, unicodeBytes);
// Convert the new byte[] into a char[] and then into a string.
char[] asciiChars = new char[utf8.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
utf8.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string Utf8string = new string(asciiChars);
// Display the strings created before and after the conversion.
Console.WriteLine("Original string: {0}", mensajeex);
Console.WriteLine("Ascii converted string: {0}", Utf8string);
return Utf8string;
}
实际上它有效!但是,当我尝试对字符串进行编码,然后像这样将异常作为 Message 属性传递时
throw new Exception(XMLHelper.ConvertToUTF8(Message));
它给了我错误的回应,例如:
El valor 'R' no es válido segú
有任何想法吗?谢谢
解决方案
推荐阅读
- swiftui - Form 和 List 两次渲染子视图
- node.js - 如何使用 reactjs 组件将数据数组发送到 mongodb?
- api - 我应该使用哪个 google oauth Playground API 来获取带有名称、用户照片和电子邮件的令牌?
- postgresql - pgAdmin 抛出错误保存属性无法连接服务器超时已过期连接到 AWS Lightsail 中的 Postgresql
- c - 为什么我的代码中出现分段错误?无法调试,请解释错误
- python - 将指标/结果组合成一个数据框 python
- java - 请求标头编码更改为空正文
- nativescript - 如何仅更新项目中的“nativescript-vue”包?
- reactjs - React UI - 从文件浏览器获取文件的绝对路径
- google-cloud-firestore - 检查用户名是否存在于firestore中并返回true swiftUI