我正在调用一个XML Web服务。我正在使用以下函数:
[System.ServiceModel.OperationContractAttribute(Action="http://onlinetools.ups.com/webservices/ShipBinding/v1.0", ReplyAction="*")]
[System.ServiceModel.FaultContractAttribute(typeof(UPS.ShipServiceReference.ErrorDetailType[]), Action="http://onlinetools.ups.com/webservices/ShipBinding/v1.0", Name="Errors", Namespace="http://www.ups.com/XMLSchema/XOLTWS/Error/v1.1")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(ShipmentServiceOptionsType))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(CompanyInfoType))]
System.Threading.Tasks.Task<UPS.ShipServiceReference.ShipmentResponse1> ProcessShipmentAsync(UPS.ShipServiceReference.ShipmentRequest1 request);
当我发送的请求没有任何错误时,结果将愉快地返回“ShipmentResponse 1”
但如果请求有问题,我无法找到如何获取错误详细信息,如Fiddler中所示:
我已经将我的代码 Package 在一个基本的try/catch(异常ex)中,但是该ex只包含“faultstring”。
我希望能够访问“PrimaryErrorCode代码和说明”,但无法找到具体方法。
如有任何帮助,我将不胜感激
1条答案
按热度按时间yquaqz181#
ProcessShipmentAsync
方法使用FaultContractAttribute
修饰,它指定错误详细信息的类型,如下所示:UPS.ShipServiceReference.ErrorDetailType[]
.要在出错时访问这些对象,必须捕获
FaultException<T>
,其中T是UPS.ShipServiceReference.ErrorDetailType[]
类型。有关详细信息,请参阅该异常的
Details
属性。