我需要反序列化SOAP错误信封
反序列化的XML:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<faultcode>9001</faultcode>
<faultstring>Some fault string</faultstring>
<faultactor>Some fault factor</faultactor>
<detail>Some Detail</detail>
</SOAP:Body>
</SOAP:Envelope>
预期的结果是将XML反序列化为以下类,但是不会对值进行反序列化,所有值都会为NULL
[XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Body
{
[XmlElement(ElementName = "faultcode")]
public string Faultcode { get; set; }
[XmlElement(ElementName = "faultstring")]
public string Faultstring { get; set; }
[XmlElement(ElementName = "faultactor")]
public string Faultactor { get; set; }
[XmlElement(ElementName = "detail")]
public string Detail { get; set; }
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(ElementName = "Body")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "SOAP", Namespace = "http://www.w3.org/2000/xmlns/")]
public string SOAP { get; set; }
}
反序列化代码:
var serializer = new XmlSerializer(typeof(Envelope));
using (TextReader reader = new StringReader(xmlString))
{
Envelope envelope = (Envelope)serializer.Deserialize(reader);
}
参考方案
命名空间必须为空字符串:
[XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Body
{
[XmlElement(ElementName = "faultcode", Namespace = "")]
public string Faultcode { get; set; }
[XmlElement(ElementName = "faultstring", Namespace = "")]
public string Faultstring { get; set; }
[XmlElement(ElementName = "faultactor", Namespace = "")]
public string Faultactor { get; set; }
[XmlElement(ElementName = "detail", Namespace = "")]
public string Detail { get; set; }
}
使用C#执行JavaScript页面 - javascript我正在尝试使用C#抓取一个网站。在此过程中的某个时候,网站返回了我需要执行的JavaScript页面,以便它将生成一些参数,然后使用所生成的参数作为查询变量来发布请求。这是JavaScript文件https://jsfiddle.net/7aw5vr59/浏览器生成的结果文件如下所示:<imimxxxyyy id="ActiveX"…
将Web用户控件添加到页面时,asp按钮onclick不会触发 - javascript我正在使用使用Visual Studio模板创建的Web表单应用程序。模板具有一个内容占位符,该占位符被访问的任何页面的内容替换。有问题的页面有几个服务器控件,例如文本框,标签和按钮。当我单击我的更新按钮时,它可以正常工作,这些值会回传并更新数据库。我想在所有子页面上创建通用的登录提示。我的导航栏(位于我的母版页中)具有引导程序设置。我在导航栏中添加了一个下…
Telerik单选按钮所需的字段验证器 - javascript如何设置Telerik单选按钮所需的字段验证器?我想在按钮单击“ BtnSave”上设置必填字段验证器吗?请帮忙!<telerik:RadButton ID="radio_male" runat="server" ToggleType="Radio" AutoPostBack="fa…
选择后显示输入元素 - javascript我有一个表格,其中取决于用户的选择,输入元素是否可见。实际上,用户正在以另一种形式设置已定义的合作伙伴类型,并且如果选中该元素,则允许在该类型的合作伙伴上可见的元素类型1将显示以下元素:<input type="text" id="partner" name="partner" class=&…
在PHP文件中调用javascript函数并在加载HTML文件之后? - javascript我需要在我的php中调用js函数,但无法正常工作。有人可以告诉我我在做什么错吗?我该如何轻松地做到这一点?谢谢!我有三个文件: mail.php负责发送$ _POST的内容(工作正常)。我调用我的javascript函数来切换模式,具体取决于邮件是否已发送。 <? ... $response = $sendgrid->send($email);…