You need to enable JavaScript to run this app. .NET Core中SOAP Fault异常无法读取Detail节点完整业务明细的问题
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core中SOAP Fault异常无法读取Detail节点完整业务明细的问题

对接接口返回的标准SOAP Fault报文
<?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>
业务需求
  • 当接口返回SOAP Fault时,需提取Detail节点包含的所有数据做后续加工,最终将处理结果返回给终端用户。
  • 当前应用基于.NET Core开发,无法使用传统框架的SoapException组件实现相关逻辑。
已尝试的实现与现存问题
  • 编写try-catch块捕获FaultException,代码如下:
try
{
    //..//
}
catch (FaultException e)
{
    MessageFault messagefault = e.CreateMessageFault();
    var xmlElement = messagefault.GetReaderAtDetailContents();
    string test = xmlElement.ReadContentAsString();
    throw e;
}

上述代码无法正确返回Detail节点包裹的内容。

  • 尝试过另一种实现:
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);

内容的提问来源于stack exchange,提问作者T.Naz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.14 17:24:03