gpt4 book ai didi

c# - 捕获 SOAP 错误并处理异常

转载 作者:行者123 更新时间:2023-11-30 14:54:34 25 4
gpt4 key购买 nike

我正在使用网络服务。有些方法在我调用时抛出异常,例如,因为参数是无效值。我想处理异常但它不包含任何数据信息,只有消息“Bad Request”。这是我的 http 响应: enter image description here

        try
{
var data = client.SomeMethod(4);
}
catch (Exception exception)
{
// exception.Message = Bad Request
// exception don't contains any more data information
}

如何获取其他信息

最佳答案

当 http 状态代码为 2xx 或 5xx 而不是 4xx 时,您可以使用 FaultException 捕获异常。您可以使用 System.ServiceModel.ProtocolException 捕获 http 状态代码 4xx,然后从 InnerException 获取流并解析它或从此流获取 FaultException。参见 http://blogs.msdn.com/b/nathana/archive/2011/03/31/deciphering-a-soap-fault-with-a-400-status-code.aspx了解更多详情。

关于c# - 捕获 SOAP 错误并处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27235601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com