如何通过在.NET中给出fallexception的tdetail来提取异常的细节?
SOAP 请求的响应是以下 xml 输出。
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">INVALID_REQUEST - Request is not a valid for XSD rules.</faultstring>
<detail>
<ServiceError xmlns="http://test.test.com/xmlschema/common">
<code>INVALID_REQUEST</code>
<description>Request is not a valid for XSD rules.</description>
<details>cvc-datatype-valid.1.2.1: '?' is not a valid value for 'integer'.</details>
<details>cvc-type.3.1.3: The value '?' of element 'pos:userId' is not valid.</details>
</ServiceError>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
在尝试使用FaultException捕获此错误时,我创建了ServiceError类,如下所示,并将其作为TDetail提供给FaultException。但是,我无法捕获此错误的详细信息。它根本不在 catch 块内。我哪里出错了或者你有推荐的方法吗?
try{
//here is the code where i got the error
}
catch (FaultException<ServiceError> e)
{
}
[DataContract]
public class ServiceError
{
[DataMember]
public string code { get; set; }
[DataMember]
public string description { get; set; }
[DataMember]
public string[] details { get; set; }
}
The response of the SOAP request is the following xml output.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">INVALID_REQUEST - Request is not a valid for XSD rules.</faultstring>
<detail>
<ServiceError xmlns="http://test.test.com/xmlschema/common">
<code>INVALID_REQUEST</code>
<description>Request is not a valid for XSD rules.</description>
<details>cvc-datatype-valid.1.2.1: '?' is not a valid value for 'integer'.</details>
<details>cvc-type.3.1.3: The value '?' of element 'pos:userId' is not valid.</details>
</ServiceError>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
While trying to catch this error with FaultException, I created the ServiceError class as below and gave it as TDetail to FaultException. However, I could not catch the details of this error.It doesn't come inside the catch block at all. Where am I going wrong or is there a method you recommend?
try{
//here is the code where i got the error
}
catch (FaultException<ServiceError> e)
{
}
[DataContract]
public class ServiceError
{
[DataMember]
public string code { get; set; }
[DataMember]
public string description { get; set; }
[DataMember]
public string[] details { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试以下方法,
消息失败的详细节点应包含 XML。
GetDetail 会将此 XML 反序列化为给定对象。有关详细信息,您可以检查 这篇文章。
内容是字符串,代码:
如果详细信息不是字符串,代码:
You can try the following method,
The detail node of the message failure should contain XML.
GetDetail will deserialize this XML into the given object.For details you can check this post.
The content is a string, the code:
If the details are not strings, the code: