Exemple #1
0
        private static ShipAcceptResponse ParseShipAcceptResponse(string xml)
        {
            ShipAcceptResponse result = new ShipAcceptResponse();

            try
            {
                XmlDocument xDoc;
                xDoc = new XmlDocument();
                xDoc.LoadXml(xml);

                XmlNode nodeResponseCode = xDoc.SelectSingleNode("ShipmentAcceptResponse/Response/ResponseStatusCode");
                if (nodeResponseCode != null)
                {
                    int responseCode = 0;
                    responseCode = int.Parse(nodeResponseCode.InnerText);
                    if (responseCode == 1)
                    {
                        result.Success = true;

                        // Parse appropriate info
                        result.TrackingNumber = XmlTools.XPathToString(ref xDoc, "ShipmentAcceptResponse/ShipmentResults/ShipmentIdentificationNumber");
                        result.BillingWeight = XmlTools.XPathToDecimal(ref xDoc, "ShipmentAcceptResponse/ShipmentResults/BillingWeight/Weight");
                        result.BillingWeightUnits = XmlTools.XPathToUnits(ref xDoc, "ShipmentAcceptResponse/ShipmentResults/BillingWeight/UnitOfMeasurement/Code");
                        result.ServiceOptionsCharge = XmlTools.XPathToDecimal(ref xDoc, "ShipmentAcceptResponse/ShipmentResults/ShipmentCharges/ServiceOptionsCharges/MonetaryValue");
                        result.ServiceOptionsChargeCurrency = XmlTools.XPathToCurrencyCode(ref xDoc, "ShipmentAcceptResponse/ShipmentResults/ShipmentCharges/ServiceOptionsCharges/CurrencyCode");
                        result.TotalCharge = XmlTools.XPathToDecimal(ref xDoc, "ShipmentAcceptResponse/ShipmentCharges/ShipmentResults/TotalCharges/MonetaryValue");
                        result.TotalChargeCurrency = XmlTools.XPathToCurrencyCode(ref xDoc, "ShipmentAcceptResponse/ShipmentResults/ShipmentCharges/TotalCharges/CurrencyCode");
                        result.TransportationCharge = XmlTools.XPathToDecimal(ref xDoc, "ShipmentAcceptResponse/ShipmentResults/ShipmentCharges/TransportationCharges/MonetaryValue");
                        result.TransportationChargeCurrency = XmlTools.XPathToCurrencyCode(ref xDoc, "ShipmentAcceptResponse/ShipmentResults/ShipmentCharges/TransportationCharges/CurrencyCode");

                        XmlNodeList packages = xDoc.SelectNodes("/ShipmentAcceptResponse/ShipmentResults/PackageResults");
                        if (packages != null)
                        {
                            ParseShipAcceptResponsePackages(ref result,ref packages);
                        }
                    }

                    else
                    {
                        result.Success = false;

                        // Parse error
                        result.ErrorMessage = XmlTools.XPathToString(ref xDoc, "ShipmentAcceptResponse/Response/Error/ErrorDescription");

                    }
                }
                else
                {
                    result.Success = false;
                    result.ErrorMessage = "Unable to Parse Response Code.";
                }
            }

            catch (Exception Exx)
            {
                result.ErrorMessage = "Parsing Error: " + Exx.Message;
                result.Success = false;
            }

            return result;
        }
Exemple #2
0
        private static void ParseShipAcceptResponsePackages(ref ShipAcceptResponse res, ref XmlNodeList packages)
        {

            foreach (XmlNode node in packages)
            {
                try
                {
                    XmlDocument xp = new XmlDocument();
                    xp.LoadXml(node.OuterXml);

                    ShippedPackageInformation _package = new ShippedPackageInformation();
                    _package.TrackingNumber = XmlTools.XPathToString(ref xp, "PackageResults/TrackingNumber");
                    _package.Base64Image = XmlTools.XPathToString(ref xp, "PackageResults/LabelImage/GraphicImage");
                    _package.Base64Html = XmlTools.XPathToString(ref xp, "PackageResults/LabelImage/HTMLImage");
                    _package.Base64Signature = XmlTools.XPathToString(ref xp, "PackageResults/InternationalSignatureGraphicImage");
                    _package.LabelFormat = XmlTools.XPathToLabelFormat(ref xp, "PackageResults/LabelImage/LabelImageFormat/Code");
                    _package.ServiceOptionsCharge = XmlTools.XPathToDecimal(ref xp, "PackageResults/ServiceOptionsCharge/MonetaryValue");
                    _package.ServiceOptionsChargeCurrency = XmlTools.XPathToCurrencyCode(ref xp, "PackageResults/ServiceOptionsCharge/CurrencyCode");
                    res.AddPackage(ref _package);
                }

                catch
                {

                }
            }
        }
Exemple #3
0
        public static ShipAcceptResponse SendShipAcceptRequest(ref ShipAcceptRequest req)
        {
            ShipAcceptResponse result = new ShipAcceptResponse();

            // Build Request and save output
            string requestXml = BuildShipAcceptRequest(ref req);
            req.XmlAcceptRequest = requestXml;

            // Build Url for UPS Service
            string actionUrl = req.Settings.ServerUrl;
            actionUrl += "ShipAccept";

            // Send Request and Store Response
            string responseXml = string.Empty;
            responseXml = XmlTools.ReadHtmlPage_POST(actionUrl, requestXml);
            req.XmlAcceptResponse = responseXml;

            // Parse Response
            result = ParseShipAcceptResponse(responseXml);

            return result;
        }