【问题标题】:Getting the details of an ONVIF FaultException获取 ONVIF FaultException 的详细信息
【发布时间】:2014-05-01 16:44:48
【问题描述】:

answer 解释了如何获取 SOAP FaultException 的文本,但它仅在内容为序列化字符串时才有效,导致<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">details</string>

然而,此 ONVIF 设备使用 SOAP <env:Text> 元素,该元素无法反序列化为字符串。

如何阅读以下FaultException的详细信息?

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:rpc="http://www.w3.org/2003/05/soap-rpc" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsa="http://www.w3.org/2005/08/addressing">
 <env:Header>
  <wsa:Action>http://www.w3.org/2005/08/addressing/soap/fault</wsa:Action>
 </env:Header>
 <env:Body>
  <env:Fault>
   <env:Code>
    <env:Value>env:Receiver</env:Value>
    <env:Subcode>
     <env:Value>ter:Action</env:Value>
    </env:Subcode>
   </env:Code>
   <env:Reason>
    <env:Text xml:lang="en">ActionFailed</env:Text>
   </env:Reason>
   <env:Detail>
    <env:Text>It is not possible to operate because of the unsupported video source mode.</env:Text>
   </env:Detail>
  </env:Fault>
 </env:Body>
</env:Envelope>

此代码来自上面的链接答案:

} catch (FaultException ex) {
    System.ServiceModel.Channels.MessageFault mf = ex.CreateMessageFault();
    if (mf.HasDetail) {
        string detailedMessage = mf.GetDetail<string>();
        output.OutputText(detailedMessage);
    }
}

失败的原因是:

类型异常 'System.Runtime.Serialization.SerializationException' 发生在 System.Runtime.Serialization.dll 但未在用户代码中处理

附加信息:期望来自命名空间的元素“字符串” 'http://schemas.microsoft.com/2003/10/Serialization/'..遇到 名称为“文本”的“元素”,命名空间 'http://www.w3.org/2003/05/soap-envelope'。

必须有一个内置的反序列化器,因为&lt;env:Reason&gt; 元素使用相同的节点。

【问题讨论】:

  • 挖掘参考源没有给出任何线索

标签: c# wcf serialization soap onvif


【解决方案1】:

您可以将详细信息作为“原始”XmlElement

System.ServiceModel.Channels.MessageFault mf = ex.CreateMessageFault();
if (mf.HasDetail) {
    System.Xml.XmlElement detailedMessage = mf.GetDetail<System.Xml.XmlElement>();
    System.Diagnostics.Trace.WriteLine("Detail: " + detailedMessage.InnerText);
}

只有在你知道内容是什么时才应该使用它,除非包装在 try { } catch { } 块中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    • 2020-10-08
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多