Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取ONVIF FaultException的详细信息_C#_Wcf_Serialization_Soap_Onvif - Fatal编程技术网

C# 获取ONVIF FaultException的详细信息

C# 获取ONVIF FaultException的详细信息,c#,wcf,serialization,soap,onvif,C#,Wcf,Serialization,Soap,Onvif,这说明了如何获取SOAPFaultException的文本,但它仅在内容是序列化字符串时起作用,从而产生详细信息 然而,这个ONVIF设备使用的是SOAP元素,它不能反序列化为字符串 如何阅读以下FaultException的详细信息 <?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:enc="http://

这说明了如何获取SOAP
FaultException
的文本,但它仅在内容是序列化字符串时起作用,从而产生
详细信息

然而,这个ONVIF设备使用的是SOAP
元素,它不能反序列化为字符串

如何阅读以下
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>

http://www.w3.org/2005/08/addressing/soap/fault
环境:接收器
三:行动
行动失败
由于不支持的视频源模式,无法运行。
此代码来自上面的链接答案:

} catch (FaultException ex) {
    System.ServiceModel.Channels.MessageFault mf = ex.CreateMessageFault();
    if (mf.HasDetail) {
        string detailedMessage = mf.GetDetail<string>();
        output.OutputText(detailedMessage);
    }
}
}捕获(FaultException-ex){
System.ServiceModel.Channels.MessageFault mf=ex.CreateMessageFault();
如果(mf.HasDetail){
字符串detailedMessage=mf.GetDetail();
output.OutputText(detailedMessage);
}
}
它失败于:

类型的例外 中发生“System.Runtime.Serialization.SerializationException” System.Runtime.Serialization.dll,但未在用户代码中处理

其他信息:应为命名空间中的元素“string” ''.. 遇到 名称为“文本”的“元素”,命名空间 ''


由于
元素使用相同的节点,因此必须有一个内置的反序列化程序。

您可以将详细信息作为“原始”
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);
}
System.ServiceModel.Channels.MessageFault mf=ex.CreateMessageFault();
如果(mf.HasDetail){
System.Xml.xmlement detailedMessage=mf.GetDetail();
System.Diagnostics.Trace.WriteLine(“详细信息:+detailedMessage.InnerText”);
}

除非包装在
try{}catch{}
块中,否则只有当您知道内容将是什么时,才应该使用此选项。

在参考源中挖掘时没有给出任何线索