private void AddPackage(string boxNo, int boxWeight, int declaredVal, int boxHeight, int boxWidth, int boxLength, string packagingTypeCode, string currencyCode, PackageType[] pkgArray, int pos) { var package = new PackageType(); var packageWeight = new PackageWeightType(); log.Debug("<<<Package info for " + boxNo + ">>>"); packageWeight.Weight = boxWeight.ToString(CultureInfo.InvariantCulture); log.Debug("Box weight: " + packageWeight.Weight); var uom = new ShipUnitOfMeasurementType(); uom.Code = "LBS"; log.Debug("Box weight unit: " + uom.Code); uom.Description = "pounds"; packageWeight.UnitOfMeasurement = uom; log.Debug("Package unit of measurement: " + uom.Description); package.PackageWeight = packageWeight; var packageDimensions = new DimensionsType(); packageDimensions.Height = boxHeight.ToString(CultureInfo.InvariantCulture); log.Debug("Package height: " + packageDimensions.Height); packageDimensions.Length = boxLength.ToString(CultureInfo.InvariantCulture); log.Debug("Package length: " + packageDimensions.Length); packageDimensions.Width = boxWidth.ToString(CultureInfo.InvariantCulture); log.Debug("Package width: " + packageDimensions.Width); var packDimType = new ShipUnitOfMeasurementType(); packDimType.Code = "IN"; packDimType.Description = "Inches"; log.Debug("Package dimension type: " + packDimType.Description + " (" + packDimType.Code + ")"); packageDimensions.UnitOfMeasurement = packDimType; package.Dimensions = packageDimensions; var packageServiceOptions = new PackageServiceOptionsType(); var declaredValue = new PackageDeclaredValueType(); declaredValue.CurrencyCode = currencyCode; log.Debug("Package declared value: " + declaredValue.CurrencyCode); declaredValue.MonetaryValue = declaredVal.ToString(CultureInfo.InvariantCulture); log.Debug("Package monetary value: " + declaredValue.MonetaryValue); packageServiceOptions.DeclaredValue = declaredValue; package.PackageServiceOptions = packageServiceOptions; var packType = new PackagingType(); packType.Description = boxNo; packType.Code = packagingTypeCode; package.Packaging = packType; pkgArray[pos] = package; }
/*private void AddPaymentInformation(ShipmentType shipment) * { * var paymentInfo = new PaymentInfoType(); * var paymentInfoType = new PaymentType(); * paymentInfoType.Code * shipper.ShipperNumber = ShipperNumber; * shipper.Name = ShipperName; * AddShipperAddress(shipper); * shipment.Shipper = shipper; * }*/ private void AddPackage(int boxWeight, int declaredVal, int boxHeight, int boxWidth, int boxLength, string packagingTypeCode, string currencyCode, PackageType[] pkgArray, int pos) { var package = new PackageType(); var packageWeight = new PackageWeightType(); packageWeight.Weight = boxWeight.ToString(); var uom = new ShipUnitOfMeasurementType(); uom.Code = "LBS"; uom.Description = "pounds"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; var packageDimensions = new DimensionsType(); packageDimensions.Height = boxHeight.ToString(); packageDimensions.Length = boxLength.ToString(); packageDimensions.Width = boxWidth.ToString(); var packDimType = new ShipUnitOfMeasurementType(); packDimType.Code = "IN"; packDimType.Description = "Inches"; packageDimensions.UnitOfMeasurement = packDimType; package.Dimensions = packageDimensions; var packageServiceOptions = new PackageServiceOptionsType(); var declaredValue = new PackageDeclaredValueType(); declaredValue.CurrencyCode = currencyCode; declaredValue.MonetaryValue = declaredVal.ToString(); packageServiceOptions.DeclaredValue = declaredValue; package.PackageServiceOptions = packageServiceOptions; var packType = new PackagingType(); packType.Code = packagingTypeCode; package.Packaging = packType; pkgArray[pos] = package; }
static void Main() { try { ShipService shpSvc = new ShipService(); ShipmentRequest shipmentRequest = new ShipmentRequest(); UPSSecurity upss = new UPSSecurity(); UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken(); upssSvcAccessToken.AccessLicenseNumber = "Your Access License"; upss.ServiceAccessToken = upssSvcAccessToken; UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken(); upssUsrNameToken.Username = "******"; upssUsrNameToken.Password = "******"; upss.UsernameToken = upssUsrNameToken; shpSvc.UPSSecurityValue = upss; RequestType request = new RequestType(); String[] requestOption = { "nonvalidate" }; request.RequestOption = requestOption; shipmentRequest.Request = request; ShipmentType shipment = new ShipmentType(); shipment.Description = "Ship webservice example"; ShipperType shipper = new ShipperType(); shipper.ShipperNumber = "Your Shipper Number"; PaymentInfoType paymentInfo = new PaymentInfoType(); ShipmentChargeType shpmentCharge = new ShipmentChargeType(); BillShipperType billShipper = new BillShipperType(); billShipper.AccountNumber = "Your Account Number"; shpmentCharge.BillShipper = billShipper; shpmentCharge.Type = "01"; ShipmentChargeType[] shpmentChargeArray = { shpmentCharge }; paymentInfo.ShipmentCharge = shpmentChargeArray; shipment.PaymentInformation = paymentInfo; ShipWSSample.ShipWebReference.ShipAddressType shipperAddress = new ShipWSSample.ShipWebReference.ShipAddressType(); String[] addressLine = { "480 Parkton Plaza" }; shipperAddress.AddressLine = addressLine; shipperAddress.City = "Timonium"; shipperAddress.PostalCode = "21093"; shipperAddress.StateProvinceCode = "MD"; shipperAddress.CountryCode = "US"; shipperAddress.AddressLine = addressLine; shipper.Address = shipperAddress; shipper.Name = "ABC Associates"; shipper.AttentionName = "ABC Associates"; ShipPhoneType shipperPhone = new ShipPhoneType(); shipperPhone.Number = "1234567890"; shipper.Phone = shipperPhone; shipment.Shipper = shipper; ShipFromType shipFrom = new ShipFromType(); ShipWSSample.ShipWebReference.ShipAddressType shipFromAddress = new ShipWSSample.ShipWebReference.ShipAddressType(); String[] shipFromAddressLine = { "Ship From Street" }; shipFromAddress.AddressLine = addressLine; shipFromAddress.City = "Timonium"; shipFromAddress.PostalCode = "21093"; shipFromAddress.StateProvinceCode = "MD"; shipFromAddress.CountryCode = "US"; shipFrom.Address = shipFromAddress; shipFrom.AttentionName = "Mr.ABC"; shipFrom.Name = "ABC Associates"; shipment.ShipFrom = shipFrom; ShipToType shipTo = new ShipToType(); ShipToAddressType shipToAddress = new ShipToAddressType(); String[] addressLine1 = { "Some Street" }; shipToAddress.AddressLine = addressLine1; shipToAddress.City = "Roswell"; shipToAddress.PostalCode = "30076"; shipToAddress.StateProvinceCode = "GA"; shipToAddress.CountryCode = "US"; shipTo.Address = shipToAddress; shipTo.AttentionName = "DEF"; shipTo.Name = "DEF Associates"; ShipPhoneType shipToPhone = new ShipPhoneType(); shipToPhone.Number = "1234567890"; shipTo.Phone = shipToPhone; shipment.ShipTo = shipTo; ServiceType service = new ServiceType(); service.Code = "01"; shipment.Service = service; PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = "10"; ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType(); uom.Code = "LBS"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; PackagingType packType = new PackagingType(); packType.Code = "02"; package.Packaging = packType; PackageType[] pkgArray = { package }; shipment.Package = pkgArray; LabelSpecificationType labelSpec = new LabelSpecificationType(); LabelStockSizeType labelStockSize = new LabelStockSizeType(); labelStockSize.Height = "6"; labelStockSize.Width = "4"; labelSpec.LabelStockSize = labelStockSize; LabelImageFormatType labelImageFormat = new LabelImageFormatType(); labelImageFormat.Code = "SPL"; labelSpec.LabelImageFormat = labelImageFormat; shipmentRequest.LabelSpecification = labelSpec; shipmentRequest.Shipment = shipment; Console.WriteLine(shipmentRequest); System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest); Console.WriteLine("The transaction was a " + shipmentResponse.Response.ResponseStatus.Description); Console.WriteLine("The 1Z number of the new shipment is " + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber); Console.ReadKey(); } catch (System.Web.Services.Protocols.SoapException ex) { Console.WriteLine(""); Console.WriteLine("---------Ship 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(" General Exception= " + ex.Message); Console.WriteLine(" General Exception-StackTrace= " + ex.StackTrace); Console.WriteLine("-------------------------"); } finally { Console.ReadKey(); } }
private string PrintLabel() { try { ShipService shpSvc = new ShipService(); ShipmentRequest shipmentRequest = new ShipmentRequest(); UPSSecurity upss = new UPSSecurity(); UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken(); upssSvcAccessToken.AccessLicenseNumber = hfLicense.Value; upss.ServiceAccessToken = upssSvcAccessToken; UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken(); upssUsrNameToken.Username = hfUserName.Value; upssUsrNameToken.Password = hfPassword.Value; upss.UsernameToken = upssUsrNameToken; shpSvc.UPSSecurityValue = upss; RequestType request = new RequestType(); String[] requestOption = { lblAddressValidation.Text.Trim() }; request.RequestOption = requestOption; shipmentRequest.Request = request; ShipmentType shipment = new ShipmentType(); shipment.Description = "CMS Label Printing"; ShipperType shipper = new ShipperType(); shipper.ShipperNumber = hfAccountNumber.Value; PaymentInfoType paymentInfo = new PaymentInfoType(); ShipmentChargeType shpmentCharge = new ShipmentChargeType(); BillShipperType billShipper = new BillShipperType(); billShipper.AccountNumber = hfAccountNumber.Value; shpmentCharge.BillShipper = billShipper; shpmentCharge.Type = lblChargeType.Text.Trim(); ShipmentChargeType[] shpmentChargeArray = { shpmentCharge }; paymentInfo.ShipmentCharge = shpmentChargeArray; shipment.PaymentInformation = paymentInfo; UPSShipWebReference.ShipAddressType shipperAddress = new UPSShipWebReference.ShipAddressType(); String[] addressLine = { lblFromStreet.Text.Trim() }; shipperAddress.AddressLine = addressLine; shipperAddress.City = lblFromCity.Text.Trim(); shipperAddress.PostalCode = lblFromZip.Text.Trim(); shipperAddress.StateProvinceCode = hfFromStateUPSCode.Value; shipperAddress.CountryCode = hfFromCountryUPSCode.Value; shipperAddress.AddressLine = addressLine; shipper.Address = shipperAddress; shipper.Name = lblFromName.Text.Trim(); shipper.AttentionName = lblFromName.Text.Trim(); ShipPhoneType shipperPhone = new ShipPhoneType(); shipperPhone.Number = lblFromPhone.Text.Trim(); shipper.Phone = shipperPhone; shipment.Shipper = shipper; ShipFromType shipFrom = new ShipFromType(); UPSShipWebReference.ShipAddressType shipFromAddress = new UPSShipWebReference.ShipAddressType(); String[] shipFromAddressLine = { lblFromStreet.Text.Trim() }; shipFromAddress.AddressLine = addressLine; shipFromAddress.City = lblFromCity.Text.Trim(); shipFromAddress.PostalCode = lblFromZip.Text.Trim(); shipFromAddress.StateProvinceCode = hfFromStateUPSCode.Value; shipFromAddress.CountryCode = hfFromCountryUPSCode.Value; shipFrom.Address = shipFromAddress; shipFrom.AttentionName = lblFromName.Text.Trim(); shipFrom.Name = lblFromName.Text.Trim(); shipment.ShipFrom = shipFrom; ShipToType shipTo = new ShipToType(); ShipToAddressType shipToAddress = new ShipToAddressType(); String[] addressLine1 = { lblToStreet.Text.Trim() }; shipToAddress.AddressLine = addressLine1; shipToAddress.City = lblToCity.Text.Trim(); shipToAddress.PostalCode = lblToZip.Text.Trim(); shipToAddress.StateProvinceCode = hfToStateUPSCode.Value; shipToAddress.CountryCode = hfToCountryUPSCode.Value; shipTo.Address = shipToAddress; shipTo.AttentionName = lblToName.Text.Trim(); shipTo.Name = lblToName.Text.Trim(); ShipPhoneType shipToPhone = new ShipPhoneType(); shipToPhone.Number = lblToPhone.Text.Trim(); shipTo.Phone = shipToPhone; shipment.ShipTo = shipTo; ServiceType service = new ServiceType(); service.Code = lblShipService.Text.Trim(); shipment.Service = service; PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = lblWeight.Text.Trim(); ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType(); uom.Code = lblMeasurementType.Text.Trim(); packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; PackagingType packType = new PackagingType(); packType.Code = lblPackagingType.Text.Trim(); package.Packaging = packType; PackageType[] pkgArray = { package }; shipment.Package = pkgArray; LabelSpecificationType labelSpec = new LabelSpecificationType(); LabelStockSizeType labelStockSize = new LabelStockSizeType(); labelStockSize.Height = "6"; labelStockSize.Width = "4"; labelSpec.LabelStockSize = labelStockSize; LabelImageFormatType labelImageFormat = new LabelImageFormatType(); labelImageFormat.Code = "GIF"; labelSpec.LabelImageFormat = labelImageFormat; shipmentRequest.LabelSpecification = labelSpec; shipmentRequest.Shipment = shipment; System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest); iTextSharp.text.Document doc = new iTextSharp.text.Document(); //Output to File string localPath = Server.MapPath("../Labels") + "\\" + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber + ".pdf"; PdfWriter.GetInstance(doc, new FileStream(localPath, FileMode.Create)); doc.Open(); Byte[] labelBuffer = System.Convert.FromBase64String(shipmentResponse.ShipmentResults.PackageResults[0].ShippingLabel.GraphicImage); MemoryStream stream = new MemoryStream(labelBuffer); iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(stream); gif.RotationDegrees = -90f; gif.ScalePercent(50f); stream.Close(); doc.NewPage(); doc.Add(gif); doc.Close(); MemoryStream output = new MemoryStream(); doc = new iTextSharp.text.Document(); PdfWriter.GetInstance(doc, output); doc.Open(); doc.NewPage(); doc.Add(gif); doc.Close(); (new OrderEntryDAL()).UploadShippingLabel_DAL("Shipping Label", output.ToArray(), "application/pdf", shipmentResponse.ShipmentResults.ShipmentIdentificationNumber + ".pdf", "", labelBuffer.Length, int.Parse(hfOrderId.Value), int.Parse(Session["UserID"].ToString())); output.Close(); return(shipmentResponse.ShipmentResults.ShipmentIdentificationNumber); } catch (System.Web.Services.Protocols.SoapException ex) { lblErr.Text = ex.Message; MPEPrepare.Show(); return(""); } catch (Exception ex) { lblErr.Text = ex.Message; MPEPrepare.Show(); return(""); } }
static void Main() { try { ShipService shpSvc = new ShipService(); ShipmentRequest shipmentRequest = new ShipmentRequest(); UPSSecurity upss = new UPSSecurity(); UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken(); upssSvcAccessToken.AccessLicenseNumber = "Your Access License"; upss.ServiceAccessToken = upssSvcAccessToken; UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken(); upssUsrNameToken.Username = "******"; upssUsrNameToken.Password = "******"; upss.UsernameToken = upssUsrNameToken; shpSvc.UPSSecurityValue = upss; RequestType request = new RequestType(); String[] requestOption = { "nonvalidate" }; request.RequestOption = requestOption; shipmentRequest.Request = request; ShipmentType shipment = new ShipmentType(); shipment.Description = "Ship webservice example"; ShipperType shipper = new ShipperType(); shipper.ShipperNumber = "Your Shipper Number"; PaymentInfoType paymentInfo = new PaymentInfoType(); ShipmentChargeType shpmentCharge = new ShipmentChargeType(); BillShipperType billShipper = new BillShipperType(); billShipper.AccountNumber = "Your Account Number"; shpmentCharge.BillShipper = billShipper; shpmentCharge.Type = "01"; ShipmentChargeType[] shpmentChargeArray = { shpmentCharge }; paymentInfo.ShipmentCharge = shpmentChargeArray; shipment.PaymentInformation = paymentInfo; ShipWSSample.ShipWebReference.ShipAddressType shipperAddress = new ShipWSSample.ShipWebReference.ShipAddressType(); String[] addressLine = { "480 Parkton Plaza" }; shipperAddress.AddressLine = addressLine; shipperAddress.City = "Timonium"; shipperAddress.PostalCode = "21093"; shipperAddress.StateProvinceCode = "MD"; shipperAddress.CountryCode = "US"; shipperAddress.AddressLine = addressLine; shipper.Address = shipperAddress; shipper.Name = "ABC Associates"; shipper.AttentionName = "ABC Associates"; ShipPhoneType shipperPhone = new ShipPhoneType(); shipperPhone.Number = "1234567890"; shipper.Phone = shipperPhone; shipment.Shipper = shipper; ShipFromType shipFrom = new ShipFromType(); ShipWSSample.ShipWebReference.ShipAddressType shipFromAddress = new ShipWSSample.ShipWebReference.ShipAddressType(); String[] shipFromAddressLine = { "Ship From Street" }; shipFromAddress.AddressLine = addressLine; shipFromAddress.City = "Timonium"; shipFromAddress.PostalCode = "21093"; shipFromAddress.StateProvinceCode = "MD"; shipFromAddress.CountryCode = "US"; shipFrom.Address = shipFromAddress; shipFrom.AttentionName = "Mr.ABC"; shipFrom.Name = "ABC Associates"; shipment.ShipFrom = shipFrom; ShipToType shipTo = new ShipToType(); ShipToAddressType shipToAddress = new ShipToAddressType(); String[] addressLine1 = { "GOERLITZER STR.1" }; shipToAddress.AddressLine = addressLine1; shipToAddress.City = "Neuss"; shipToAddress.PostalCode = "41456"; shipToAddress.CountryCode = "DE"; shipTo.Address = shipToAddress; shipTo.AttentionName = "DEF"; shipTo.Name = "DEF Associates"; ShipPhoneType shipToPhone = new ShipPhoneType(); shipToPhone.Number = "1234567890"; shipTo.Phone = shipToPhone; shipment.ShipTo = shipTo; ServiceType service = new ServiceType(); service.Code = "08"; shipment.Service = service; ShipmentTypeShipmentServiceOptions shpServiceOptions = new ShipmentTypeShipmentServiceOptions(); /** **** International Forms ***** */ InternationalFormType internationalForms = new InternationalFormType(); /** **** Commercial Invoice ***** */ String[] formTypeList = { "01" }; internationalForms.FormType = formTypeList; /** **** Contacts and Sold To ***** */ ContactType contacts = new ContactType(); SoldToType soldTo = new SoldToType(); soldTo.Option = "1"; soldTo.AttentionName = "Sold To Attn Name"; soldTo.Name = "Sold To Name"; PhoneType soldToPhone = new PhoneType(); soldToPhone.Number = "1234567890"; soldToPhone.Extension = "1234"; soldTo.Phone = soldToPhone; AddressType soldToAddress = new AddressType(); String[] soldToAddressLine = { "34 Queen St" }; soldToAddress.AddressLine = soldToAddressLine; soldToAddress.City = "Frankfurt"; soldToAddress.PostalCode = "60547"; soldToAddress.CountryCode = "DE"; soldTo.Address = soldToAddress; contacts.SoldTo = soldTo; internationalForms.Contacts = contacts; /** **** Product ***** */ ProductType product1 = new ProductType(); String[] description = { "Product 1" }; product1.Description = description; product1.CommodityCode = "111222AA"; product1.OriginCountryCode = "US"; UnitType unit = new UnitType(); unit.Number = "147"; unit.Value = "478"; UnitOfMeasurementType uomProduct = new UnitOfMeasurementType(); uomProduct.Code = "BOX"; uomProduct.Description = "BOX"; unit.UnitOfMeasurement = uomProduct; product1.Unit = unit; ProductWeightType productWeight = new ProductWeightType(); productWeight.Weight = "10"; UnitOfMeasurementType uomForWeight = new UnitOfMeasurementType(); uomForWeight.Code = "LBS"; uomForWeight.Description = "LBS"; productWeight.UnitOfMeasurement = uomForWeight; product1.ProductWeight = productWeight; ProductType[] productList = { product1 }; internationalForms.Product = productList; /** **** InvoiceNumber, InvoiceDate, PurchaseOrderNumber, TermsOfShipment, ReasonForExport, Comments and DeclarationStatement ***** */ internationalForms.InvoiceNumber = "asdf123"; internationalForms.InvoiceDate = "20151225"; internationalForms.PurchaseOrderNumber = "999jjj777"; internationalForms.TermsOfShipment = "CFR"; internationalForms.ReasonForExport = "Sale"; internationalForms.Comments = "Your Comments"; internationalForms.DeclarationStatement = "Your Declaration Statement"; /** **** Discount, FreightCharges, InsuranceCharges, OtherCharges and CurrencyCode ***** */ IFChargesType discount = new IFChargesType(); discount.MonetaryValue = "100"; internationalForms.Discount = discount; IFChargesType freight = new IFChargesType(); freight.MonetaryValue = "50"; internationalForms.FreightCharges = freight; IFChargesType insurance = new IFChargesType(); insurance.MonetaryValue = "200"; internationalForms.InsuranceCharges = insurance; OtherChargesType otherCharges = new OtherChargesType(); otherCharges.MonetaryValue = "50"; otherCharges.Description = "Misc"; internationalForms.OtherCharges = otherCharges; internationalForms.CurrencyCode = "USD"; shpServiceOptions.InternationalForms = internationalForms; shipment.ShipmentServiceOptions = shpServiceOptions; PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = "10"; ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType(); uom.Code = "LBS"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; PackagingType packType = new PackagingType(); packType.Code = "02"; package.Packaging = packType; PackageType[] pkgArray = { package }; shipment.Package = pkgArray; LabelSpecificationType labelSpec = new LabelSpecificationType(); LabelStockSizeType labelStockSize = new LabelStockSizeType(); labelStockSize.Height = "6"; labelStockSize.Width = "4"; labelSpec.LabelStockSize = labelStockSize; LabelImageFormatType labelImageFormat = new LabelImageFormatType(); labelImageFormat.Code = "GIF"; labelSpec.LabelImageFormat = labelImageFormat; shipmentRequest.LabelSpecification = labelSpec; shipmentRequest.Shipment = shipment; Console.WriteLine(shipmentRequest); System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest); Console.WriteLine("The transaction was a " + shipmentResponse.Response.ResponseStatus.Description); Console.WriteLine("The 1Z number of the new shipment is " + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber); Console.ReadKey(); } catch (System.Web.Services.Protocols.SoapException ex) { Console.WriteLine(""); Console.WriteLine("---------Ship 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(" General Exception= " + ex.Message); Console.WriteLine(" General Exception-StackTrace= " + ex.StackTrace); Console.WriteLine("-------------------------"); } finally { Console.ReadKey(); } }
public void CreateShipmentRequest() { try { ShipService shipService = new ShipService(); ShipmentRequest shipmentRequest = new ShipmentRequest(); // Security UPSSecurity upss = new UPSSecurity(); UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken { AccessLicenseNumber = "1CBF3AD5FB29C105" }; upss.ServiceAccessToken = upssSvcAccessToken; UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken(); if (radioButton_PLZFT.Checked == true) { upssUsrNameToken.Username = "******"; upssUsrNameToken.Password = "******"; } else { upssUsrNameToken.Username = "******"; // AAC upssUsrNameToken.Password = "******"; // AAC } upss.UsernameToken = upssUsrNameToken; shipService.UPSSecurityValue = upss; // Request RequestType request = new RequestType(); shipmentRequest.Request = request; // Request Option String[] requestOption = { "nonvalidate" }; request.RequestOption = requestOption; shipmentRequest.Request = request; // Shipment ShipmentType shipment = new ShipmentType(); shipment.Description = "Amazon Gift Card"; // Shipper ShipperType shipper = new ShipperType(); //shipper.ShipperNumber = "9E6741"; //if (radioButton_PLZFT.Checked == true) shipper.ShipperNumber = "9E6741"; // <- gleich dem im AccessToken !? //else // 9E6741 // shipper.ShipperNumber = "9E6741"; // <- gleich dem im AccessToken !? // Payment Info PaymentInfoType paymentInfo = new PaymentInfoType(); ShipmentChargeType shipmentCharge = new ShipmentChargeType(); shipmentCharge.Type = "01"; //Payment Info -> BillShipper BillShipperType billShipper = new BillShipperType(); //billShipper.AccountNumber = "9E6741"; billShipper.AccountNumber = "587997"; shipmentCharge.BillShipper = billShipper; ShipmentChargeType shipmentCharge2 = new ShipmentChargeType(); shipmentCharge2.Type = "02"; // Payment Info -> BillReceiver BillReceiverType billReceiver = new BillReceiverType(); billReceiver.AccountNumber = "9E6741"; shipmentCharge2.BillReceiver = billReceiver; // Payment Info -> Bill3rdParty //BillThirdPartyChargeType bill3rdParty = new BillThirdPartyChargeType(); //bill3rdParty.AccountNumber = "9E6741"; //AccountAddressType thirdPartyAddress = new AccountAddressType //{ // PostalCode = "94032", // CountryCode = "DE" //}; //bill3rdParty.Address = thirdPartyAddress; //shipmentCharge2.BillThirdParty = bill3rdParty; ShipmentChargeType[] shpmentChargeArray = { shipmentCharge, shipmentCharge2 }; //ShipmentChargeType[] shpmentChargeArray = { shipmentCharge2 }; //ShipmentChargeType[] shpmentChargeArray = { shipmentCharge2 }; paymentInfo.ShipmentCharge = shpmentChargeArray; // Shipment -> Payment Information shipment.PaymentInformation = paymentInfo; // Shipper UPS_API.ShipWebReference.ShipAddressType shipperAddress = new UPS_API.ShipWebReference.ShipAddressType(); String[] addressLine = { textBox_Shipper_AddressLine.Text }; shipperAddress.AddressLine = addressLine; shipperAddress.City = textBox_Shipper_City.Text; shipperAddress.PostalCode = textBox_Shipper_PostalCode.Text; shipperAddress.StateProvinceCode = textBox_Shipper_StateProvince.Text; shipperAddress.CountryCode = textBox_Shipper_CountryCode.Text; shipperAddress.AddressLine = addressLine; shipper.Address = shipperAddress; shipper.Name = textBox_Shipper_Name.Text; shipper.AttentionName = textBox_Shipper_AttentionName.Text; ShipPhoneType shipperPhone = new ShipPhoneType(); shipperPhone.Number = textBox_Shipper_PhoneNumber.Text; shipper.Phone = shipperPhone; // Shipment -> Shipper shipment.Shipper = shipper; // ShipFrom ShipFromType shipFrom = new ShipFromType(); UPS_API.ShipWebReference.ShipAddressType shipFromAddress = new UPS_API.ShipWebReference.ShipAddressType(); String[] shipFromAddressLine = { textBox_ShipFrom_AddressLine.Text }; shipFromAddress.AddressLine = addressLine; shipFromAddress.City = textBox_ShipFrom_City.Text; shipFromAddress.PostalCode = textBox_ShipFrom_PostalCode.Text; shipFromAddress.StateProvinceCode = textBox_ShipFrom_StateProvince.Text; shipFromAddress.CountryCode = textBox_ShipFrom_CountryCode.Text; shipFrom.Address = shipFromAddress; shipFrom.Name = textBox_ShipFrom_Name.Text; shipFrom.AttentionName = textBox_ShipFrom_AttentionName.Text; ShipPhoneType shipFromPhone = new ShipPhoneType(); shipFromPhone.Number = textBox_ShipFrom_PhoneNumber.Text; shipFrom.Phone = shipFromPhone; // Shipment -> ShipFrom shipment.ShipFrom = shipFrom; // ShipTo ShipToType shipTo = new ShipToType(); ShipToAddressType shipToAddress = new ShipToAddressType(); String[] addressLine1 = { textBox_ShipTo_AddressLine1.Text }; shipToAddress.AddressLine = addressLine1; shipToAddress.City = textBox_ShipTo_City.Text; shipToAddress.PostalCode = textBox_ShipTo_PostalCode.Text; shipToAddress.StateProvinceCode = textBox_ShipTo_StateProvince.Text; shipToAddress.CountryCode = textBox_ShiptTo_CountryCode.Text; shipTo.Address = shipToAddress; shipTo.Name = textBox_ShipTo_Name.Text; shipTo.AttentionName = textBox_ShipTo_AttentionName.Text; ShipPhoneType shipToPhone = new ShipPhoneType(); shipToPhone.Number = textBox_ShipTo_PhoneNumber.Text; shipTo.Phone = shipToPhone; // Shipment -> ShipTo shipment.ShipTo = shipTo; // Services ServiceType service = new ServiceType(); service.Code = "11"; //ShipmentServiceOptionsType shipmentServiceOptions = new ShipmentServiceOptionsType(); // Shipment -> Services shipment.Service = service; // Package PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = textBox_Package_Weight.Text; ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType(); uom.Code = textBox_Package_MeasurementCode.Text; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; PackagingType packType = new PackagingType(); packType.Code = textBox_Package_TypeCode.Text; package.Packaging = packType; PackageType[] pkgArray = { package }; // Shipment -> Package shipment.Package = pkgArray; // Label LabelSpecificationType labelSpec = new LabelSpecificationType(); LabelStockSizeType labelStockSize = new LabelStockSizeType(); labelStockSize.Height = "6"; labelStockSize.Width = "4"; labelSpec.LabelStockSize = labelStockSize; LabelImageFormatType labelImageFormat = new LabelImageFormatType(); labelImageFormat.Code = "PNG"; labelSpec.LabelImageFormat = labelImageFormat; // Shipment Request -> Label shipmentRequest.LabelSpecification = labelSpec; // Shipment Request -> Shipment shipmentRequest.Shipment = shipment; // Request -> Execute richTextBox1.Text += shipmentRequest + "\r\n"; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11; //This line will ensure the latest security protocol for consuming the web service call. ShipmentResponse shipmentResponse = shipService.ProcessShipment(shipmentRequest); string shipmentIdentificationNumber = shipmentResponse.ShipmentResults.ShipmentIdentificationNumber; richTextBox1.Text += "The transaction was a " + shipmentResponse.Response.ResponseStatus.Description + "\r\n"; richTextBox1.Text += "The 1Z number of the new shipment is " + shipmentIdentificationNumber + "\r\n"; textBox_ShipmentIdentificationNumber.Text = shipmentIdentificationNumber; // Save label as PNG string base64Label = shipmentResponse.ShipmentResults.PackageResults[0].ShippingLabel.GraphicImage; byte[] data = Convert.FromBase64String(base64Label); using (var stream = new MemoryStream(data, 0, data.Length)) { Image imageLabel = Image.FromStream(stream); pictureBox_Label.Image = imageLabel; pictureBox_Label.Image.RotateFlip(RotateFlipType.Rotate90FlipNone); imageLabel.Save(Path.Combine(@Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "ups_" + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber + ".png")); } textBox_ErrorLog.ForeColor = Color.LimeGreen; textBox_ErrorLog.Text = "OK"; } catch (System.Web.Services.Protocols.SoapException ex) { textBox_ErrorLog.ForeColor = Color.Salmon; textBox_ErrorLog.Text = ex.Detail.LastChild.InnerText; richTextBox1.Text += "\r\n"; richTextBox1.Text += "---------Ship Web Service returns error----------------\r\n"; richTextBox1.Text += "---------\"Hard\" is user error \"Transient\" is system error----------------\r\n"; richTextBox1.Text += "SoapException Message= " + ex.Message; richTextBox1.Text += "\r\n"; richTextBox1.Text += "SoapException Category:Code:Message= " + ex.Detail.LastChild.InnerText; richTextBox1.Text += "\r\n"; richTextBox1.Text += "SoapException XML String for all= " + ex.Detail.LastChild.OuterXml; richTextBox1.Text += "\r\n"; richTextBox1.Text += "SoapException StackTrace= " + ex.StackTrace; richTextBox1.Text += "-------------------------\r\n"; richTextBox1.Text += "\r\n"; } catch (System.ServiceModel.CommunicationException ex) { textBox_ErrorLog.ForeColor = Color.Salmon; textBox_ErrorLog.Text = ex.Message; richTextBox1.Text += "\r\n"; richTextBox1.Text += "--------------------\r\n"; richTextBox1.Text += "CommunicationException= " + ex.Message; richTextBox1.Text += "CommunicationException-StackTrace= " + ex.StackTrace; richTextBox1.Text += "-------------------------\r\n"; richTextBox1.Text += "\r\n"; } catch (Exception ex) { textBox_ErrorLog.ForeColor = Color.Salmon; textBox_ErrorLog.Text = ex.Message; richTextBox1.Text += "\r\n"; richTextBox1.Text += "-------------------------\r\n"; richTextBox1.Text += " General Exception= " + ex.Message; richTextBox1.Text += " General Exception-StackTrace= " + ex.StackTrace; richTextBox1.Text += "-------------------------\r\n"; } finally { } }
private static void ScheduleShipment() { try { ShipService shpSvc = new ShipService(); ShipmentRequest shipmentRequest = new ShipmentRequest(); // security UPSSecurity upss = new UPSSecurity(); UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken(); upssSvcAccessToken.AccessLicenseNumber = "4CF6E9703C30E4B6"; upss.ServiceAccessToken = upssSvcAccessToken; UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken(); upssUsrNameToken.Username = "******"; upssUsrNameToken.Password = "******"; upss.UsernameToken = upssUsrNameToken; shpSvc.UPSSecurityValue = upss; RequestType request = new RequestType(); String[] requestOption = { "nonvalidate" }; request.RequestOption = requestOption; shipmentRequest.Request = request; ShipmentType shipment = new ShipmentType(); shipment.Description = "New shipment ..."; // payment PaymentInfoType paymentInfo = new PaymentInfoType(); ShipmentChargeType shpmentCharge = new ShipmentChargeType(); BillShipperType billShipper = new BillShipperType(); billShipper.AccountNumber = "1YA077"; shpmentCharge.BillShipper = billShipper; shpmentCharge.Type = "01"; ShipmentChargeType[] shpmentChargeArray = { shpmentCharge }; paymentInfo.ShipmentCharge = shpmentChargeArray; shipment.PaymentInformation = paymentInfo; // shipper ShipperType shipper = new ShipperType(); shipper.ShipperNumber = "1YA077"; ShipWSSample.ShipWebReference.ShipAddressType shipperAddress = new ShipWSSample.ShipWebReference.ShipAddressType(); String[] addressLine = { "88 Foster Crescent" }; shipperAddress.AddressLine = addressLine; shipperAddress.City = "Mississauga"; shipperAddress.PostalCode = "L5R4A2"; shipperAddress.StateProvinceCode = "ON"; shipperAddress.CountryCode = "CA"; shipper.Address = shipperAddress; shipper.Name = "CATO"; shipper.AttentionName = "Ingram Micro - Mississauga"; ShipPhoneType shipperPhone = new ShipPhoneType(); shipperPhone.Number = "1234567890"; shipper.Phone = shipperPhone; shipment.Shipper = shipper; // ship from ShipFromType shipFrom = new ShipFromType(); ShipWSSample.ShipWebReference.ShipAddressType shipFromAddress = new ShipWSSample.ShipWebReference.ShipAddressType(); String[] shipFromAddressLine = { "135 Liberty St. Suite 101" }; shipFromAddress.AddressLine = addressLine; shipFromAddress.City = "Toronto"; shipFromAddress.PostalCode = "M6K1A7"; shipFromAddress.StateProvinceCode = "ON"; shipFromAddress.CountryCode = "CA"; shipFrom.Address = shipFromAddress; shipFrom.AttentionName = "Mr. Andy Feng"; shipFrom.Name = "Kobo Inc."; shipment.ShipFrom = shipFrom; // ship to ShipToType shipTo = new ShipToType(); ShipToAddressType shipToAddress = new ShipToAddressType(); String[] addressLine1 = { "403 Burr Oak Drive" }; shipToAddress.AddressLine = addressLine1; shipToAddress.City = "Oswego"; shipToAddress.PostalCode = "60543"; shipToAddress.StateProvinceCode = "IL"; shipToAddress.CountryCode = "US"; shipTo.Address = shipToAddress; shipTo.AttentionName = "Mr. John Smith"; shipTo.Name = "DEF Associates"; ShipPhoneType shipToPhone = new ShipPhoneType(); shipToPhone.Number = "(905) 123-1234"; shipTo.Phone = shipToPhone; shipment.ShipTo = shipTo; //service ServiceType service = new ServiceType(); //service.Code = "01"; // next day air service.Code = "11";//ups standard shipment.Service = service; // package PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = "10"; ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType(); uom.Code = "LBS"; packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; PackagingType packType = new PackagingType(); packType.Code = "02"; package.Packaging = packType; // package 2 PackageType package2 = new PackageType(); PackageWeightType packageWeight2 = new PackageWeightType(); packageWeight2.Weight = "9"; ShipUnitOfMeasurementType uom2 = new ShipUnitOfMeasurementType(); uom2.Code = "LBS"; packageWeight2.UnitOfMeasurement = uom2; package2.PackageWeight = packageWeight2; PackagingType packType2 = new PackagingType(); packType2.Code = "02"; package2.Packaging = packType2; PackageType[] pkgArray = { package, package2 }; shipment.Package = pkgArray; // add delivery confirmation for package level //PackageServiceOptionsType packageServiceOptions = new PackageServiceOptionsType(); //package.PackageServiceOptions = packageServiceOptions; //package2.PackageServiceOptions = packageServiceOptions; //DeliveryConfirmationType deliveryConfirmation = new DeliveryConfirmationType(); ////Service DCIS Type, The type of confirmation required upon delivery of the package. //deliveryConfirmation.DCISType = "2"; //Delivery Confirmation Signature Required //// The delivery confirmation control number that confirms the package's delivery. ////deliveryConfirmation.DCISNumber = "xxxxxxxx"; //packageServiceOptions.DeliveryConfirmation = deliveryConfirmation; // label LabelSpecificationType labelSpec = new LabelSpecificationType(); LabelStockSizeType labelStockSize = new LabelStockSizeType(); labelStockSize.Height = "1"; labelStockSize.Width = "1"; labelSpec.LabelStockSize = labelStockSize; LabelImageFormatType labelImageFormat = new LabelImageFormatType(); //// for zpl //labelStockSize.Height = "6"; //labelStockSize.Width = "4"; //labelImageFormat.Code = "ZPL"; // for gif labelImageFormat.Code = "GIF"; labelSpec.LabelImageFormat = labelImageFormat; shipmentRequest.LabelSpecification = labelSpec; shipmentRequest.Shipment = shipment; // label ShipmentTypeShipmentServiceOptions options = new ShipmentTypeShipmentServiceOptions(); //options.LabelDelivery = new LabelDeliveryType(); shipment.ShipmentServiceOptions = options; // international form for paperless invoice InternationalFormType internationalForm = new InternationalFormType(); internationalForm.AdditionalDocumentIndicator = null; internationalForm.ReasonForExport = "SALE"; internationalForm.ExportDate = DateTime.Now.ToString("yyyyMMdd"); internationalForm.ExportingCarrier = "UPS"; internationalForm.InvoiceDate = DateTime.Now.ToString("yyyyMMdd"); internationalForm.CurrencyCode = "CAD"; internationalForm.FormType = new String[] { "01" }; internationalForm.Contacts = new ContactType() { SoldTo = new SoldToType() { Name = "andy", Address = new AddressType() { AddressLine = new String[] { "box 40" }, City = "Tornnn", CountryCode = "US", PostalCode = "M1S2S5", StateProvinceCode = "ON" } } }; internationalForm.Product = new ProductType[] { new ProductType() { ProducerInfo = "product1", Description = new String[] { "1233" }, Unit = new UnitType() { Number = "1", UnitOfMeasurement = new UnitOfMeasurementType() { Code = "BG" }, Value = "1" }, OriginCountryCode = "CA", CommodityCode = "123456", NumberOfPackagesPerCommodity = "1", ProductWeight = new ProductWeightType() { UnitOfMeasurement = new UnitOfMeasurementType() { Code = "LBS" }, Weight = "12" } } }; options.InternationalForms = internationalForm; // delivery confirmation for shipment level DeliveryConfirmationType deliveryConfirmation = new DeliveryConfirmationType(); deliveryConfirmation.DCISType = "2"; options.DeliveryConfirmation = deliveryConfirmation; Console.WriteLine(shipmentRequest); System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); // response ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest); Console.WriteLine("The transaction was a " + shipmentResponse.Response.ResponseStatus.Description); // output label base64 characters string byteFileName = @"c:\Users\afeng\Pictures\label.txt"; using (FileStream fs = new FileStream(byteFileName, FileMode.Create, FileAccess.ReadWrite)) { using (BinaryWriter sw = new BinaryWriter(fs)) { sw.Write(shipmentResponse.ShipmentResults.PackageResults.FirstOrDefault().ShippingLabel.GraphicImage); } } // output label image string filename = @"c:\Users\afeng\Pictures\label.gif"; byte[] byteLabel; using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite)) { using (BinaryWriter writer = new BinaryWriter(fs)) { byteLabel = Convert.FromBase64String( shipmentResponse.ShipmentResults.PackageResults.FirstOrDefault().ShippingLabel.GraphicImage); writer.Write(byteLabel); } } // output label html page string htmlFilename = @"c:\Users\afeng\Pictures\label.html"; byte[] htmlByteLabel; using (FileStream fs = new FileStream(htmlFilename, FileMode.Create, FileAccess.ReadWrite)) { using (BinaryWriter writer = new BinaryWriter(fs)) { htmlByteLabel = Convert.FromBase64String( shipmentResponse.ShipmentResults.PackageResults.FirstOrDefault().ShippingLabel.HTMLImage); writer.Write(htmlByteLabel); } } // binary serialize Stream stream = File.Open(@"c:\Users\afeng\Pictures\data.dat", FileMode.Create); BinaryFormatter bformatter = new BinaryFormatter(); Console.WriteLine("Writing binary serialize Information"); bformatter.Serialize(stream, shipmentResponse); stream.Close(); // xml serialize Stream requetStream = File.Open(@"c:\Users\afeng\Pictures\request.xml", FileMode.Create); XmlSerializer requestSerializer = new XmlSerializer(shipment.GetType()); Console.WriteLine("Writing xml serialize Information"); requestSerializer.Serialize(requetStream, shipment); requetStream.Close(); Stream responseStream = File.Open(@"c:\Users\afeng\Pictures\response.xml", FileMode.Create); XmlSerializer serializer = new XmlSerializer(shipmentResponse.GetType()); Console.WriteLine("Writing xml serialize Information"); serializer.Serialize(responseStream, shipmentResponse); responseStream.Close(); // resize picture int width = (int)(8.25 * 72); int height = (int)(4.25 * 72); // resize picture 1 Bitmap imgIn = new Bitmap(filename); double y = imgIn.Height; double x = imgIn.Width; double factor = 1; if (width > 0) { factor = width / x; } else if (height > 0) { factor = height / y; } System.IO.MemoryStream outStream = new System.IO.MemoryStream(); Bitmap imgOut = new Bitmap((int)(x * factor), (int)(y * factor)); // Set DPI of image (xDpi, yDpi) //imgOut.SetResolution(72, 72); imgOut.SetResolution(96, 96); Graphics g = Graphics.FromImage(imgOut); g.Clear(Color.White); g.DrawImage(imgIn, new Rectangle(0, 0, (int)(factor * x), (int)(factor * y)), new Rectangle(0, 0, (int)x, (int)y), GraphicsUnit.Pixel); imgOut.Save(outStream, ImageFormat.Gif); string filename2 = @"c:\Users\afeng\Pictures\label2.gif"; FileStream fs2 = new FileStream(filename2, FileMode.Create, FileAccess.ReadWrite); BinaryWriter writer2 = new BinaryWriter(fs2); writer2.Write(outStream.ToArray()); writer2.Close(); // resize picture 2 //Creates a new Bitmap as the size of the window Bitmap bmp = new Bitmap(width, height); //Creates a new graphics to handle the image that is coming from the stream Graphics g2 = Graphics.FromImage((Image)bmp); g2.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g2.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; //Resizes the image from the stream to fit our windows Bitmap imgIn2 = new Bitmap(filename); g2.DrawImage(imgIn2, 0, 0, width, height); string filename3 = @"c:\Users\afeng\Pictures\label3.gif"; FileStream fs3 = new FileStream(filename3, FileMode.Create, FileAccess.ReadWrite); BinaryWriter writer3 = new BinaryWriter(fs3); System.IO.MemoryStream outStream2 = new System.IO.MemoryStream(); bmp.Save(outStream2, ImageFormat.Gif); writer3.Write(outStream2.ToArray()); writer3.Close(); // resize picture 3 Bitmap newImage = new Bitmap(width, height); using (Graphics gr = Graphics.FromImage(newImage)) { gr.SmoothingMode = SmoothingMode.HighQuality; //gr.InterpolationMode = InterpolationMode.HighQualityBicubic; gr.InterpolationMode = InterpolationMode.NearestNeighbor; gr.PixelOffsetMode = PixelOffsetMode.HighQuality; gr.DrawImage(new Bitmap(filename), new Rectangle(0, 0, width, height)); string filename4 = @"c:\Users\afeng\Pictures\label4.gif"; FileStream fs4 = new FileStream(filename4, FileMode.Create, FileAccess.ReadWrite); //newImage.Save(filename4, System.Drawing.Imaging.ImageFormat.Gif); BinaryWriter writer4 = new BinaryWriter(fs4); System.IO.MemoryStream outStream4 = new System.IO.MemoryStream(); newImage.Save(outStream4, ImageFormat.Gif); writer4.Write(outStream4.ToArray()); writer4.Close(); } // resize picture 4 ImageHandler ih = new ImageHandler(); string filename5 = @"c:\Users\afeng\Pictures\label5.jpg"; MemoryStream stream5 = new MemoryStream(); stream5.Write(byteLabel, 0, byteLabel.Length); //Bitmap b = new Bitmap(filename); Bitmap b = new Bitmap(stream5); ih.Save(b, width, height, 100, filename5); Console.WriteLine("The 1Z number of the new shipment is " + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber); Console.ReadKey(); } catch (System.Web.Services.Protocols.SoapException ex) { Console.WriteLine(""); Console.WriteLine("---------Ship 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(" General Exception= " + ex.Message); Console.WriteLine(" General Exception-StackTrace= " + ex.StackTrace); Console.WriteLine("-------------------------"); } finally { Console.ReadKey(); } }