c# - 从故障异常中获取详细信息不显示完整的详细信息
问题描述
我有以下格式的 xml 文件:
<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Receiver</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">Cannot create order</soap:Text>
</soap:Reason>
<soap:Detail>
<ComplianceViolationInfos xmlns="http://aaim.sungard.com/order/service/v1_0" xmlns:ns10="http://aaim.sungard.com/issuer/schema/v2011_06_01" xmlns:ns2="http://aaim.sungard.com/datatypes/schema/v2011_06_01" xmlns:ns3="http://aaim.sungard.com/order/schema/v2011_06_01" xmlns:ns4="http://aaim.sungard.com/fxorder/schema/v2011_06_01" xmlns:ns5="http://aaim.sungard.com/portfolio/schema/v2011_06_01" xmlns:ns6="http://aaim.sungard.com/transaction/schema/v2011_06_01" xmlns:ns7="http://aaim.sungard.com/compliance/schema/v2011_06_01" xmlns:ns8="http://aaim.sungard.com/user/schema/v2011_06_01" xmlns:ns9="http://aaim.sungard.com/instrument/schema/v2011_06_01">
<ns7:violationInfo>
<ns7:RuleType>REQ_OVERRIDE</ns7:RuleType>
<ns7:RuleName> Name </ns7:RuleName>
<ns7:Diagnostic> data </ns7:Diagnostic>
</ns7:violationInfo>
<ns7:violationInfo>
<ns7:RuleType> rule </ns7:RuleType>
<ns7:RuleName> data </ns7:RuleName>
<ns7:Diagnostic>1. data </ns7:Diagnostic>
</ns7:violationInfo>
<ns7:violationInfo>
<ns7:RuleType>WARNING</ns7:RuleType>
<ns7:RuleName> name </ns7:RuleName>
<ns7:Diagnostic> data </ns7:Diagnostic>
</ns7:violationInfo>
</ComplianceViolationInfos>
</soap:Detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
在发生故障的情况下,我想访问位于 details 标志之间的所有数据,进一步处理它,然后将其返回给用户。我正在开发一个 .NET Core 应用程序,因此我不能使用 SoapExceptions。为了实现这一点,我的代码中有一个 try-catch-blog,它捕获了一个故障异常:
try
{
//..//
}
catch (FaultException e)
{
MessageFault messagefault = e.CreateMessageFault();
var xmlElement = messagefault.GetReaderAtDetailContents();
string test = xmlElement.ReadContentAsString();
throw e;
}
上面的代码不返回详细标志之间的数据。我也已经尝试过:
string xmlElement = messagefault.GetDetail<XmlElement>().Value
这返回了一个空字符串。
我认为原因是我无法弄清楚该服务的 wcf 中的错误。序列化的类是:
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://aaim.sungard.com/compliance/schema/v2011_06_01")]
public partial class ComplianceViolationInfo
{
private ViolationInfo[] ViolationInfoField;
[System.Xml.Serialization.XmlArrayAttribute(Order = 0)]
[System.Xml.Serialization.XmlArrayItemAttribute("violationInfo", IsNullable = false)]
public ViolationInfo[] ViolationInfo
{
get
{
return this.ViolationInfoField;
}
set
{
this.ViolationInfoField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://aaim.sungard.com/compliance/schema/v2011_06_01")]
public partial class ViolationInfo
{
private string ruleTypeField;
private string ruleNameField;
private string diagnosticField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order = 0)]
public string RuleType
{
get
{
return this.ruleTypeField;
}
set
{
this.ruleTypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order = 1)]
public string RuleName
{
get
{
return this.ruleNameField;
}
set
{
this.ruleNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order = 2)]
public string Diagnostic
{
get
{
return this.diagnosticField;
}
set
{
this.diagnosticField = value;
}
}
}
它是这样调用的:
[System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
[System.ServiceModel.FaultContractAttribute(typeof(OrderService.ComplianceViolationInfo), Action="", Name="ComplianceViolationInfos", Namespace="http://aaim.sungard.com/order/service/v1_0")]
[System.ServiceModel.FaultContractAttribute(typeof(OrderService.FaultInfo), Action = "", Name = "FaultInfo", Namespace = "http://aaim.sungard.com/order/service/v1_0")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
System.Threading.Tasks.Task<OrderService.CreateOrderResponse1> CreateOrderAsync(OrderService.CreateOrderRequest request);
解决方案
推荐阅读
- ios - QuickBlox 视频未获得视频流
- swift - 当我不断增加它们的大小时,我试图让我的按钮居中?
- css - 当我关闭 Chrome devtools 中的 CSS 规则然后再次打开时,绝对定位的元素会改变位置
- wordpress - 我的客户需要域和托管在不同的托管服务提供商
- asp.net-mvc - Syncfusion MVC Datagrid - 如何在行中显示按钮
- javascript - node.js、express.js 和 mysql - 无法读取未定义的属性“状态”
- javascript - {{}} 我在 html 脚本标签中找到了这个
- mysql - 如何在 2 个表中进行计数
- spring-cloud-dataflow - 自定义处理器流程的 Http 引发 org.springframework.expression.spel.SpelEvaluationException: EL1004E
- wso2 - 如何通过 WSO2-API 管理器传递 CKAN API 授权令牌