我已經將我的代碼包裝在一個基本的 try/catch (Exception ex) 中,但 ex 只包含“faultstring”。
我希望能夠獲得“PrimaryErrorCode 代碼和描述”,但無法弄清楚如何去做。
任何幫助將不勝感激
uj5u.com熱心網友回復:
該ProcessShipmentAsync方法用 a 裝飾FaultContractAttribute,它指定錯誤詳細資訊的型別,此處為 : UPS.ShipServiceReference.ErrorDetailType[]。
[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"
)]
要在發生錯誤時訪問這些,您必須捕獲 a FaultException<T>,其中 T 是該UPS.ShipServiceReference.ErrorDetailType[]型別。
詳細資訊可在該Details例外的屬性上獲得。
catch (FaultException<UPS.ShipServiceReference.ErrorDetailType[]> ex)
{
// Access ex.Details.
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/410161.html
標籤:
