對此的答案可能是非常明顯的。但需要一些幫助...需要原始XML請求和響應在UPS API(.Net)
我目前使用UPS API /服務來生成測試標籤。一切都很好。但要獲得認證,我必須向UPS發送請求&響應中的原始XML。
我不是發送原始xml,而是使用服務及其各種屬性。發貨結果中是否有原始XML返回?或者必須手動序列化請求&響應才能滿足UPS在其審閱中需要的內容?
這裏是我的代碼(一切正常,我能夠產生一個標籤,但我如何才能請求&響應XML?)
try
{
ShipService shpSvc = new ShipService();
ShipmentRequest shipmentRequest = new ShipmentRequest();
UPSSecurity upss = new UPSSecurity();
UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
upssSvcAccessToken.AccessLicenseNumber = s.APIKey;
upss.ServiceAccessToken = upssSvcAccessToken;
UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
upssUsrNameToken.Username = s.Username;
upssUsrNameToken.Password = s.Password;
upss.UsernameToken = upssUsrNameToken;
shpSvc.UPSSecurityValue = upss;
RequestType request = new RequestType();
String[] requestOption = { "nonvalidate" };
request.RequestOption = requestOption;
shipmentRequest.Request = request;
ShipmentType shipment = new ShipmentType();
ShipperType shipper = new ShipperType();
shipper.ShipperNumber = s.ShipperAccountNumber;
PaymentInfoType paymentInfo = new PaymentInfoType();
ShipmentChargeType shpmentCharge = new ShipmentChargeType();
BillShipperType billShipper = new BillShipperType();
billShipper.AccountNumber = s.ShipperAccountNumber;
shpmentCharge.BillShipper = billShipper;
shpmentCharge.Type = "01";
ShipmentChargeType[] shpmentChargeArray = { shpmentCharge };
paymentInfo.ShipmentCharge = shpmentChargeArray;
shipment.PaymentInformation = paymentInfo;
ShipWebReference.ShipAddressType shipperAddress = new ShipWebReference.ShipAddressType();
String[] addressLine = { s.ShipperAddressLine };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = s.ShipperCity;
shipperAddress.PostalCode = s.ShipperZip;
shipperAddress.StateProvinceCode = s.ShipperState;
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;
shipper.Name = s.ShipperName;
shipper.AttentionName = s.ShipperName;
ShipPhoneType shipperPhone = new ShipPhoneType();
shipperPhone.Number = s.ShipperPhone;
shipper.Phone = shipperPhone;
shipment.Shipper = shipper;
ShipFromType shipFrom = new ShipFromType();
ShipWebReference.ShipAddressType shipFromAddress = new ShipWebReference.ShipAddressType();
String[] shipFromAddressLine = { s.ShipperAddressLine };
shipFromAddress.AddressLine = addressLine;
shipFromAddress.City = s.ShipperCity;
shipFromAddress.PostalCode = s.ShipperZip;
shipFromAddress.StateProvinceCode = s.ShipperState;
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;
shipFrom.AttentionName = s.ShipperName;
shipFrom.Name = s.ShipperName;
shipment.ShipFrom = shipFrom;
ShipToType shipTo = new ShipToType();
ShipToAddressType shipToAddress = new ShipToAddressType();
String[] addressLine1 = { s.ShipToAddressLine };
shipToAddress.AddressLine = addressLine1;
shipToAddress.City = s.ShipToCity;
shipToAddress.PostalCode = s.ShipToZip;
shipToAddress.StateProvinceCode = s.ShipToState;
shipToAddress.CountryCode = "US";
shipTo.Address = shipToAddress;
shipTo.AttentionName = s.ShipToName;
shipTo.Name = s.ShipToName;
ShipPhoneType shipToPhone = new ShipPhoneType();
shipToPhone.Number = s.ShipToPhone;
shipTo.Phone = shipToPhone;
shipment.ShipTo = shipTo;
ServiceType service = new ServiceType();
service.Code = "03";
shipment.Service = service;
PackageType package = new PackageType();
PackageWeightType packageWeight = new PackageWeightType();
packageWeight.Weight = s.PackageWeight;
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();
LabelDeliveryType labelDel = new LabelDeliveryType();
labelDel.LabelLinksIndicator = "";
labelImageFormat.Code = "GIF";
PackageServiceOptionsType packServiceOptions = new PackageServiceOptionsType();
PackageDeclaredValueType decType = new PackageDeclaredValueType();
decType.CurrencyCode = "USD";
decType.MonetaryValue = s.PackageValue;
packServiceOptions.DeclaredValue = decType;
package.PackageServiceOptions = packServiceOptions;
labelSpec.LabelImageFormat = labelImageFormat;
ShipmentTypeShipmentServiceOptions shipServOpt = new ShipmentTypeShipmentServiceOptions();
shipment.ShipmentServiceOptions = shipServOpt;
shipmentRequest.LabelSpecification = labelSpec;
shipmentRequest.Shipment = shipment;
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
Console.WriteLine(shipmentRequest);
shipmentResponse = shpSvc.ProcessShipment(shipmentRequest);
}