これに対する答えは、痛いほど明白かもしれません。しかし、助けが必要です...
現在、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);
}