Пример #1
0
        /// <summary>
        /// Post请求DHL接口
        /// </summary>
        /// <param name="ap">ShipmentValidateRequestAP实例</param>
        /// <param name="serverUrl">请求DHL接口的服务地址</param>
        /// <returns></returns>
        public ShipmentValidateResponse PostDHLShipment(ShipmentValidateRequestAP ap, string serverUrl)
        {
            var ns = new XmlSerializerNamespaces();

            ns.Add("req", "http://www.dhl.com");
            var responseResult = HttpHelper.PostSendRequest(ap, serverUrl, ns);

            try
            {
                var response = SerializeUtil.DeserializeFromXml <ShipmentValidateResponse>(responseResult);
                return(response);
            }
            catch (InvalidOperationException ex)
            {
                try
                {
                    var result = SerializeUtil.DeserializeFromXml <ShipmentValidateErrorResponse>(responseResult);
                    if (result != null)
                    {
                        throw new BusinessLogicException(result.Response.Status.Condition[0].ConditionData);
                    }
                }
                catch (InvalidOperationException ioex)
                {
                    var errorResult = SerializeUtil.DeserializeFromXml <LMS.Data.Express.DHL.Response.ErrorResponse>(responseResult);
                    if (errorResult != null)
                    {
                        throw new BusinessLogicException(errorResult.Response.Status.Condition[0].ConditionData);
                    }
                }
            }
            return(null);
        }
Пример #2
0
        public void DHLShipmentRequest()
        {
            ShipmentValidateRequestAP ap = new ShipmentValidateRequestAP()
            {
                Billing = new Billing()
                {
                    DutyPaymentType      = DutyTaxPaymentType.R,
                    ShipperAccountNumber = "550000055",
                    ShippingPaymentType  = ShipmentPaymentType.S
                },
                Commodity = new[]
                {
                    new Commodity()
                    {
                        CommodityCode = "111111",
                        CommodityName = "xiaoming"
                    }
                },
                Consignee = new Consignee()     //收货人
                {
                    AddressLine = new[]
                    {
                        "2711 St", "Appt 211"
                    },
                    City        = "RedWood City",
                    CompanyName = "Prasanta INC",
                    Contact     = new Contact()
                    {
                        //Email = new Email()
                        //{
                        //    Body = "*****@*****.**",
                        //    cc = new[] { "String", "String" },
                        //    From = "*****@*****.**",
                        //    ReplyTo = "String",
                        //    Subject = "String",
                        //    To = "*****@*****.**"
                        //},
                        PersonName     = "Prasanta Sinha",
                        FaxNumber      = "11234325423",
                        PhoneExtension = 45232,
                        PhoneNumber    = "11234325423",
                        Telex          = "454586"
                    },
                    CountryCode  = "US",
                    CountryName  = "United States of America",
                    DivisionCode = "CA",
                    PostalCode   = "94065"
                },
                Dutiable = new Dutiable()
                {
                    DeclaredCurrency = "USD",
                    DeclaredValue    = "50.11",
                    ShipperEIN       = "Text"
                },
                LanguageCode  = "en",
                PiecesEnabled = PiecesEnabled.Y,
                Reference     = new[]
                {
                    new Reference()
                    {
                        ReferenceID   = "String",
                        ReferenceType = "St"
                    }
                },
                Request = new Request()
                {
                    ServiceHeader = new ServiceHeader()
                    {
                        MessageReference = "1234567890123456789012345678901",
                        //MessageTime = DateTime.Parse("2011-10-27T15:28:56.000-08:00"),
                        Password = "******",
                        SiteID   = "DServiceVal"
                    }
                },
                ShipmentDetails = new ShipmentDetails()     //出货详情
                {
                    Contents          = "For testing purpose only. Please do not ship",
                    CurrencyCode      = "USD",
                    Date              = DateTime.Parse("2014-04-06"),
                    DimensionUnit     = DimensionUnit.C,
                    DoorTo            = DoorTo.DD,
                    GlobalProductCode = "P",
                    LocalProductCode  = "P",
                    NumberOfPieces    = 1,
                    PackageType       = PackageType.EE,
                    Weight            = (decimal)0.5,
                    WeightUnit        = WeightUnit.K,
                    //InsuredAmount = "10000",
                    Pieces = new[]
                    {
                        new Piece
                        {
                            // PieceID = "String",
                            Depth = 2,
                            // DimWeight = (decimal)2.111,
                            Height = 2,
                            //PackageType = PackageType.EE,
                            Weight = (decimal)0.5,
                            Width  = 2
                        }
                    }
                },
                Shipper = new Shipper()     //发货人
                {
                    ShipperID   = "550000055",
                    AddressLine = new[] { "333 Twin" },
                    City        = "Kuala Lumpur",
                    CompanyName = "Santa inc",
                    Contact     = new Contact()
                    {
                        //Email = new Email()
                        //{
                        //    Body = "*****@*****.**",
                        //    cc = new[] { "String" },
                        //    From = "*****@*****.**",
                        //    ReplyTo = "*****@*****.**",
                        //    Subject = "String",
                        //    To = "*****@*****.**"
                        //},
                        PersonName     = "santa santa",
                        FaxNumber      = "17456356365",
                        PhoneExtension = 6536,
                        PhoneNumber    = "15356456364",
                        Telex          = "74558"
                    },
                    CountryCode  = "MY",
                    CountryName  = "Malaysia",
                    DivisionCode = "KL",
                    PostalCode   = "94065"
                }
            };

            var ns = new XmlSerializerNamespaces();

            ns.Add("req", "http://www.dhl.com");
            string url            = "https://xmlpitest-ea.dhl.com/XMLShippingServlet";
            var    responseResult = HttpHelper.PostSendRequest(ap, url, ns);

            try
            {
                var response =
                    SerializeUtil.DeserializeFromXml <LMS.Data.Express.DHL.Response.ShipmentValidateResponse>(
                        responseResult);

                Assert.IsNotNull(response);
            }
            catch (Exception)
            {
                var response =
                    SerializeUtil.DeserializeFromXml <LMS.Data.Express.DHL.Response.Error.ShipmentValidateErrorResponse>(
                        responseResult);

                Assert.Fail();
            }
        }