private RateResponse CallUPSRateRequest(string scode, int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, decimal unitPrice, RateService upsService)
        {
            RateResponse rateResponse = new RateResponse();
            try
            {
                RateRequest rateRequest = new RateRequest();
                AddCustomerClassification(rateRequest);
                AddUpsSecurity(upsService);
                UPS_Shipping_Rate.UPSRateService.RequestType request = new RequestType();
                String[] requestOption = { "Rate" };
                request.RequestOption = requestOption;
                rateRequest.Request = request;
                ShipmentType shipment = new ShipmentType();
                AddShipper(shipment);
                AddShipFromAddress(shipment);
                AddShipToAddress(shipment);
                UPS_Shipping_Rate.UPSRateService.CodeDescriptionType service = new UPS_Shipping_Rate.UPSRateService.CodeDescriptionType();
                service.Code = scode.ToString();
                shipment.Service = service;
                ShipmentRatingOptionsType optype = new ShipmentRatingOptionsType();
                optype.NegotiatedRatesIndicator = string.Empty;
                shipment.ShipmentRatingOptions = optype;
                AddPackageArray(nrBoxes, itemsInLastBox, fullBoxWeight, partialBoxWeight, valuePerFullBox, valuePerPartialBox, details, shipment);
                AddInvoiceTotalType(Qty, unitPrice, shipment);
                rateRequest.Shipment = shipment;
                //  ServicePointManager.ServerCertificateValidationCallback = ValidateRemoteCertificate;
                rateResponse = upsService.ProcessRate(rateRequest);
            }
            catch (Exception ex)
            {

            }
            return rateResponse;
        }
        private void GetRateFromUPS(int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, decimal unitPrice)
        {
            try
            {
                List<Result> lst = new List<Result>();
                lst.Add(new Result() { service = "UPS Next Day Air®", code = "01" });
                lst.Add(new Result() { service = "UPS Second Day Air®", code = "02" });
                lst.Add(new Result() { service = "UPS Ground", code = "03" });
                lst.Add(new Result() { service = "UPS Express", code = "07" });
                lst.Add(new Result() { service = "UPS ExpeditedSM", code = "08" });
                lst.Add(new Result() { service = "UPS Standard", code = "11" });
                lst.Add(new Result() { service = "UPS Three-Day Select®", code = "12" });
                lst.Add(new Result() { service = "UPS Next Day Air Saver®", code = "13" });
                lst.Add(new Result() { service = "UPS Next Day Air® Early A.M. SM", code = "14" });

                foreach (Result r in lst)
                {
                    RateService upsService = new RateService();
                    try
                    {
                        RateResponse rateResponse = CallUPSRateRequest(r.code, Qty, nrBoxes, itemsInLastBox, fullBoxWeight, valuePerFullBox, valuePerPartialBox, partialBoxWeight, details, unitPrice, upsService);
                        if (rateResponse.RatedShipment != null)
                        {
                            foreach (var rshipment in rateResponse.RatedShipment)
                            {
                                r.cost = rshipment.NegotiatedRateCharges.TotalCharge.MonetaryValue + " " + rshipment.NegotiatedRateCharges.TotalCharge.CurrencyCode;
                                if (rshipment.GuaranteedDelivery != null && rshipment.GuaranteedDelivery.BusinessDaysInTransit != null)
                                    r.time = rshipment.GuaranteedDelivery.BusinessDaysInTransit + " days";
                            }
                        }
                    }
                    catch (System.Web.Services.Protocols.SoapException ex)
                    {

                    }
                }
                //lstView.DataSource = lst;
                //lstView.DataBind();

                //Display the response data
                ViewBag.ResultList = lst;
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {

            }
        }
 private static void AddUpsSecurity(RateService upsService)
 {
     UPS_Shipping_Rate.UPSRateService.UPSSecurity upss = new UPS_Shipping_Rate.UPSRateService.UPSSecurity();
     AddUpsServiceAccessToken(upss);
     AddUserNameToken(upss);
     upsService.UPSSecurityValue = upss;
 }