2014-06-09 3 views
0

UPS API를 사용하여 배송 라벨을 작성하려고합니다. UPS api는 webservice를 사용하여 XML 요청을 UPS에 보냅니다. 그런 다음 UPS는 응답을 되돌려 보냅니다. 여기에 내 질문이있다.C#에서 XML 출력보기

"shipmentRequest"메소드를 호출 할 때 출력되는 XML을 볼 수있는 방법이 있습니까?

API와 웹 서비스를 처음 사용하기 때문에 더 많은 정보를 제공해 주시면 알려드립니다.

감사합니다.

편집 : 여기 내 C# 코드

내가 당신을 도울 수도 있습니다 코드 표시 XML을 사용하고
   ShipService shpSvc = new ShipService(); 
      ShipmentRequest shipmentRequest = new ShipmentRequest(); 
      UPSSecurity upss = new UPSSecurity(); 
      //shpSvc.Url = "https://onlinetools.ups.com/webservices/Ship"; 
      UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken(); 
      upssSvcAccessToken.AccessLicenseNumber = apiCode; 
      upss.ServiceAccessToken = upssSvcAccessToken; 
      UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken(); 
      upssUsrNameToken.Username = userName; 
      upssUsrNameToken.Password = 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 = accountNumber; 
      PaymentInfoType paymentInfo = new PaymentInfoType(); 
      ShipmentChargeType shpmentCharge = new ShipmentChargeType(); 
      BillShipperType billShipper = new BillShipperType(); 
      billShipper.AccountNumber = accountNumber; 
      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 = "1"; 
      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; 
      ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest); 
      MessageBox.Show("The transaction was a " + shipmentResponse.Response.ResponseStatus.Description); 
      MessageBox.Show("The 1Z number of the new shipment is " + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber); 
+0

지금까지 수행 한 작업에 C# 코드를 표시 할 수 있습니까? – cvraman

+0

당신은 xml – KarthikManoharan

+0

을 표시하기 위해 textarea를 사용할 수 있습니다. 그래서 나는 Shipment Request.Shipment에 발송물을 지정할 때 요청이 전송되고 있다고 가정합니다. 그 맞습니까? – mattc19

답변

2

당신은 UPS 서비스에서 상속 GetWriterForMessage()를 재정 의하여 자신의 XmlWriter를 제공함으로써 XML로 응답을 읽을 수 있습니다. 작업 예제 here을 볼 수 있습니다.

+0

흥미 롭습니다! 내가 그것을 작동시킬 수 있는지보기 위해 이것을 시도 할 것이다. 감사! – mattc19

1

입니다.

 XDocument mySourceDoc = new XDocument(); 
     mySourceDoc = XDocument.Load(shipmentResponse); 
     txtxml.Text = mySourceDoc.ToString(); 
+0

감사합니다 !! 나는 지금 이것을 시도하고있다. recieveStream 및 txtxml에 사용해야하는 네임 스페이스를 알고 있습니까? – mattc19

+0

업데이트 된 코드 사용 – KarthikManoharan

+0

XDocument.Load 줄에 오류가 발생합니다. "System.Xml.Linq.XDocument.Load (System.Xml.XmlReader)에 대한 최상의 오버로드 된 메서드 일치에는 잘못된 인수가 있습니다."응답이 XML 형식이 아니라는 것을 의미합니다. – mattc19