public List <ShippingOption> GetShippingOptions() { var shippingOptions = new List <ShippingOption>(); try { var service = new RateService(); RateRequest request = CreateRateRequest(service); RateResponse rateResponse = service.ProcessRate(request); shippingOptions = ParseAnswer(rateResponse); } catch (System.Web.Services.Protocols.SoapException ex) { Debug.LogError(ex, false); } catch (System.ServiceModel.CommunicationException ex) { Debug.LogError(ex, false); } catch (Exception ex) { Debug.LogError(ex); } return(shippingOptions); }
public RateResponse CallUPSRateRequest(string serviceCode, int Qty, int nrBoxes, int itemsInLastBox, string fullBoxWeight, int valuePerFullBox, int valuePerPartialBox, string partialBoxWeight, inv_detl details, string packagingTypeCode, string currencyCode, decimal unitPrice, bool isResidentialAddress)//, out string requestXML) { var upsService = new RateService(); var rateResponse = new RateResponse(); var rateRequest = new RateRequest(); AddCustomerClassification(rateRequest); AddUpsSecurity(upsService); var request = new RequestType(); String[] requestOption = { "Rate" }; request.RequestOption = requestOption; //this can be Rate or Shop rateRequest.Request = request; var shipment = new UPSRateService.ShipmentType(); AddShipper(shipment); AddShipFromAddress(shipment); AddShipToAddress(shipment, isResidentialAddress); var service = new CodeDescriptionType(); service.Code = serviceCode; shipment.Service = service; var optype = new UPSRateService.ShipmentRatingOptionsType(); optype.NegotiatedRatesIndicator = string.Empty; shipment.ShipmentRatingOptions = optype; AddPackageArray(nrBoxes, itemsInLastBox, fullBoxWeight, partialBoxWeight, valuePerFullBox, valuePerPartialBox, details, packagingTypeCode, currencyCode, shipment); AddInvoiceTotalType(Qty, unitPrice, shipment); rateRequest.Shipment = shipment; rateResponse = upsService.ProcessRate(rateRequest); return(rateResponse); }
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); }
static void Main() { try { RateService rate = new RateService(); RateRequest rateRequest = new RateRequest(); UPSSecurity upss = new UPSSecurity(); UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken(); upssSvcAccessToken.AccessLicenseNumber = "Your Access License Number"; upss.ServiceAccessToken = upssSvcAccessToken; UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken(); upssUsrNameToken.Username = "******"; upssUsrNameToken.Password = "******"; upss.UsernameToken = upssUsrNameToken; rate.UPSSecurityValue = upss; RequestType request = new RequestType(); String[] requestOption = { "Rate" }; request.RequestOption = requestOption; rateRequest.Request = request; ShipmentType shipment = new ShipmentType(); ShipperType shipper = new ShipperType(); shipper.ShipperNumber = "Your Shipper Number"; RateWSSample.RateWebReference.AddressType shipperAddress = new RateWSSample.RateWebReference.AddressType(); String[] addressLine = { "5555 main", "4 Case Cour", "Apt 3B" }; shipperAddress.AddressLine = addressLine; shipperAddress.City = "Roswell"; shipperAddress.PostalCode = "30076"; shipperAddress.StateProvinceCode = "GA"; shipperAddress.CountryCode = "US"; shipperAddress.AddressLine = addressLine; shipper.Address = shipperAddress; shipment.Shipper = shipper; ShipFromType shipFrom = new ShipFromType(); RateWSSample.RateWebReference.AddressType shipFromAddress = new RateWSSample.RateWebReference.AddressType(); shipFromAddress.AddressLine = addressLine; shipFromAddress.City = "Roswell"; shipFromAddress.PostalCode = "30076"; shipFromAddress.StateProvinceCode = "GA"; shipFromAddress.CountryCode = "US"; shipFrom.Address = shipFromAddress; shipment.ShipFrom = shipFrom; ShipToType shipTo = new ShipToType(); ShipToAddressType shipToAddress = new ShipToAddressType(); String[] addressLine1 = { "10 E. Ritchie Way", "2", "Apt 3B" }; shipToAddress.AddressLine = addressLine1; shipToAddress.City = "Plam Springs"; shipToAddress.PostalCode = "92262"; shipToAddress.StateProvinceCode = "CA"; shipToAddress.CountryCode = "US"; shipTo.Address = shipToAddress; shipment.ShipTo = shipTo; CodeDescriptionType service = new CodeDescriptionType(); //Below code uses dummy date for reference. Please udpate as required. service.Code = "02"; shipment.Service = service; PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = "125"; CodeDescriptionType uom = new CodeDescriptionType(); uom.Code = "LBS"; uom.Description = "pounds"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; CodeDescriptionType packType = new CodeDescriptionType(); packType.Code = "02"; package.PackagingType = packType; PackageType[] pkgArray = { package }; shipment.Package = pkgArray; rateRequest.Shipment = shipment; System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); Console.WriteLine(rateRequest); RateResponse rateResponse = rate.ProcessRate(rateRequest); Console.WriteLine("The transaction was a " + rateResponse.Response.ResponseStatus.Description); Console.WriteLine("Total Shipment Charges " + rateResponse.RatedShipment[0].TotalCharges.MonetaryValue + rateResponse.RatedShipment[0].TotalCharges.CurrencyCode); Console.ReadKey(); } catch (System.Web.Services.Protocols.SoapException ex) { Console.WriteLine(""); Console.WriteLine("---------Rate Web Service returns error----------------"); Console.WriteLine("---------\"Hard\" is user error \"Transient\" is system error----------------"); Console.WriteLine("SoapException Message= " + ex.Message); Console.WriteLine(""); Console.WriteLine("SoapException Category:Code:Message= " + ex.Detail.LastChild.InnerText); Console.WriteLine(""); Console.WriteLine("SoapException XML String for all= " + ex.Detail.LastChild.OuterXml); Console.WriteLine(""); Console.WriteLine("SoapException StackTrace= " + ex.StackTrace); Console.WriteLine("-------------------------"); Console.WriteLine(""); } catch (System.ServiceModel.CommunicationException ex) { Console.WriteLine(""); Console.WriteLine("--------------------"); Console.WriteLine("CommunicationException= " + ex.Message); Console.WriteLine("CommunicationException-StackTrace= " + ex.StackTrace); Console.WriteLine("-------------------------"); Console.WriteLine(""); } catch (Exception ex) { Console.WriteLine(""); Console.WriteLine("-------------------------"); Console.WriteLine(" Generaal Exception= " + ex.Message); Console.WriteLine(" Generaal Exception-StackTrace= " + ex.StackTrace); Console.WriteLine("-------------------------"); } finally { Console.ReadKey(); } }
public static double UPSEstimatedRate(Person shipto, ProductCollection cart) { double temp = 0.0; //return 0.0 if something is wrong try { RateService rate = new RateService(); RateRequest rateRequest = new RateRequest(); UPSSecurity upss = new UPSSecurity(); UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken(); upssSvcAccessToken.AccessLicenseNumber = ConfigurationManager.AppSettings["UPSAccessLicenseNumber"]; upss.ServiceAccessToken = upssSvcAccessToken; UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken(); upssUsrNameToken.Username = ConfigurationManager.AppSettings["UPSUserName"]; upssUsrNameToken.Password = ConfigurationManager.AppSettings["UPSPassword"]; upss.UsernameToken = upssUsrNameToken; rate.UPSSecurityValue = upss; RequestType request = new RequestType(); String[] requestOption = { "Rate" }; request.RequestOption = requestOption; rateRequest.Request = request; ShipmentType shipment = new ShipmentType(); ShipperType shipper = new ShipperType(); shipper.ShipperNumber = "54A177"; //***EAC Intentionally hard-coded. DO NOT REPLACE WITH ONE IN WEB.CONFIG! UPSRateService.AddressType shipperAddress = new UPSRateService.AddressType(); String[] addressLine = { ConfigurationManager.AppSettings["LMStreet"] }; shipperAddress.AddressLine = addressLine; shipperAddress.City = ConfigurationManager.AppSettings["LMCity"]; shipperAddress.StateProvinceCode = ConfigurationManager.AppSettings["LMState"]; shipperAddress.PostalCode = ConfigurationManager.AppSettings["LMZip"]; shipperAddress.CountryCode = ConfigurationManager.AppSettings["LMCountry"]; shipperAddress.AddressLine = addressLine; shipper.Address = shipperAddress; shipment.Shipper = shipper; ShipFromType shipFrom = new ShipFromType(); //UPSRateService.AddressType shipFromAddress = new UPSRateService.AddressType(); //shipFromAddress.AddressLine = shipperAddress.AddressLine; //shipFromAddress.City = shipperAddress.City; //shipFromAddress.StateProvinceCode = shipperAddress.StateProvinceCode; //shipFromAddress.PostalCode = shipperAddress.PostalCode; //shipFromAddress.CountryCode = shipperAddress.CountryCode; shipFrom.Address = shipperAddress; shipment.ShipFrom = shipFrom; ShipToType shipTo = new ShipToType(); ShipToAddressType shipToAddress = new ShipToAddressType(); String[] addressLine1 = { shipto.Addr1 }; shipToAddress.AddressLine = addressLine1; shipToAddress.City = shipto.City; shipToAddress.StateProvinceCode = shipto.State; shipToAddress.PostalCode = shipto.Zip5; shipToAddress.CountryCode = shipto.Country; shipTo.Address = shipToAddress; shipment.ShipTo = shipTo; CodeDescriptionType service = new CodeDescriptionType(); //Below code uses dummy date for reference. Please udpate as required. //service.Code = "03"; //01:nextdayair 02;2ndday 03:ground 12:3dayselect service.Code = DAL2.DAL.GetShippingMethodValuebyID(cart.ShipMethod); shipment.Service = service; PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = cart.TotalWeight.ToString(); CodeDescriptionType uom = new CodeDescriptionType(); uom.Code = "LBS"; uom.Description = "pounds"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; CodeDescriptionType packType = new CodeDescriptionType(); packType.Code = "02"; //02:pkgcustomer package.PackagingType = packType; PackageType[] pkgArray = { package }; shipment.Package = pkgArray; rateRequest.Shipment = shipment; System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); RateResponse rateResponse = rate.ProcessRate(rateRequest); UPSNoelWrite("The transaction was a " + rateResponse.Response.ResponseStatus.Description); UPSNoelWrite("Total Shipment Charges " + rateResponse.RatedShipment[0].TotalCharges.MonetaryValue + rateResponse.RatedShipment[0].TotalCharges.CurrencyCode); temp = Double.Parse(rateResponse.RatedShipment[0].TotalCharges.MonetaryValue); } catch (Exception ex) { temp = 0.0; } return(temp); //catch (System.Web.Services.Protocols.SoapException ex) //{ // UPSNoelWrite(""); // UPSNoelWrite("---------Rate Web Service returns error----------------"); // UPSNoelWrite("---------\"Hard\" is user error \"Transient\" is system error----------------"); // UPSNoelWrite("SoapException Message= " + ex.Message); // UPSNoelWrite(""); // UPSNoelWrite("SoapException Category:Code:Message= " + ex.Detail.LastChild.InnerText); // UPSNoelWrite(""); // UPSNoelWrite("SoapException XML String for all= " + ex.Detail.LastChild.OuterXml); // UPSNoelWrite(""); // UPSNoelWrite("SoapException StackTrace= " + ex.StackTrace); // UPSNoelWrite("-------------------------"); // UPSNoelWrite(""); //} //catch (System.ServiceModel.CommunicationException ex) //{ // UPSNoelWrite(""); // UPSNoelWrite("--------------------"); // UPSNoelWrite("CommunicationException= " + ex.Message); // UPSNoelWrite("CommunicationException-StackTrace= " + ex.StackTrace); // UPSNoelWrite("-------------------------"); // UPSNoelWrite(""); //} //catch (Exception ex) //{ // UPSNoelWrite(""); // UPSNoelWrite("-------------------------"); // UPSNoelWrite(" Generaal Exception= " + ex.Message); // UPSNoelWrite(" Generaal Exception-StackTrace= " + ex.StackTrace); // UPSNoelWrite("-------------------------"); //} //finally //{ // //Console.ReadKey(); //} }
public List<ShippingOption> GetShippingOptions() { var shippingOptions = new List<ShippingOption>(); try { var service = new RateService(); RateRequest request = CreateRateRequest(service); RateResponse rateResponse = service.ProcessRate(request); shippingOptions = ParseAnswer(rateResponse); } catch (System.Web.Services.Protocols.SoapException ex) { Debug.LogError(ex, false); } catch (System.ServiceModel.CommunicationException ex) { Debug.LogError(ex, false); } catch (Exception ex) { Debug.LogError(ex); } return shippingOptions; }