Fedex WebServices Soap Request within Classic ASP page

时间:2017-06-15 10:01:23

标签: soap asp-classic fedex

I want to use FedEx web services to book a shipment, currently getting the error response back.

soapenv:ServerBEA-382000: java.lang.NullPointerExceptionBEA-382000java.lang.NullPointerExceptionrequest-pipelinetrue

Code within fedextest.asp

 <% Set oXmlHTTP =  CreateObject("MSXML2.ServerXMLHTTP")

oXmlHTTP.Open "GET", "https://wsbeta.fedex.com:443/web-services", False


oXmlHTTP.setRequestHeader "Content-Type", "application/soap+xml;    charset=utf-8" 
oXmlHTTP.setRequestHeader "SOAPAction", "https://wsbeta.fedex.com:443/web-    services"
SOAPRequest = "<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" &_
"<soap:Body>" &_
"<ProcessShipmentRequest xmlns=""https://wsbeta.fedex.com:443/web-services"">" &_
"<WebAuthenticationDetail>" &_
"<UserCredential>" &_
"<Key>1fufGShbz33hZ0ld</Key>" &_
"<Password>3WuWhLQheoF9yoCu9XV851XYn</Password>" &_
"</UserCredential>" &_
"</WebAuthenticationDetail>" &_
"<ClientDetail>" &_
"<AccountNumber>700636402</AccountNumber>" &_
"<MeterNumber>118700937</MeterNumber>" &_
"</ClientDetail>" &_
"<TransactionDetail>" &_
"<CustomerTransactionId>TransactionID_WS1</CustomerTransactionId>" &_
"</TransactionDetail>" &_
"<Version>" &_
"<ServiceId>ship</ServiceId>" &_
"<Major>17</Major>" &_
"<Intermediate>0</Intermediate>" &_
"<Minor>0</Minor>" &_
"</Version>" &_
"<RequestedShipment>" &_
"<ShipTimestamp>2016-02-17T15:56:03</ShipTimestamp>" &_
"<DropoffType>REGULAR_PICKUP</DropoffType>" &_
"<ServiceType>FEDEX_NEXT_DAY_EARLY_MORNING</ServiceType>" &_
"<PackagingType>YOUR_PACKAGING</PackagingType>" &_
"<TotalWeight>" &_
"<Units>KG</Units>" &_
"<Value>10</Value>" &_
"</TotalWeight>" &_
"<Shipper>" &_
"<Contact>" &_
"<PersonName>Paul Cullen</PersonName>" &_
"<CompanyName>Bundle International</CompanyName>" &_
"<PhoneNumber>01782563322</PhoneNumber>" &_
"<EMailAddress>paulcullen@fedex.com</EMailAddress>" &_
"</Contact>" &_
"<Address>" &_
"<StreetLines>Unit 5 Dewar Close</StreetLines>" &_
"<StreetLines>Segensworth West</StreetLines>" &_
"<City>Fareham</City>" &_
"<StateOrProvinceCode/>" &_
"<PostalCode>PO15 5UB</PostalCode>" &_
"<CountryCode>GB</CountryCode>" &_
"</Address>" &_
"</Shipper>" &_
"<Recipient>" &_
"<Contact>" &_
"<PersonName>GDE TEST (POD NEEDED)</PersonName>" &_
"<CompanyName>Joe Bloggs</CompanyName>" &_
"<PhoneNumber>01782563322</PhoneNumber>" &_
"<EMailAddress/>" &_
"</Contact>" &_
"<Address>" &_
"<StreetLines>Parkhouse Industrial Estate</StreetLines>" &_
"<StreetLines/>" &_
"<City>Newcastle Under Lyme</City>" &_
"<StateOrProvinceCode/>" &_
"<PostalCode>ST5 7RB</PostalCode>" &_
"<CountryCode>GB</CountryCode>" &_
"</Address>" &_
"</Recipient>" &_
"<ShippingChargesPayment>" &_
"<PaymentType>SENDER</PaymentType>" &_
"<Payor>" &_
"<ResponsibleParty>" &_
"<AccountNumber>700636402</AccountNumber>" &_
"<Contact/>" &_
"</ResponsibleParty>" &_
"</Payor>" &_
"</ShippingChargesPayment>" &_
"<CustomsClearanceDetail>" &_
"<DutiesPayment>" &_
"<PaymentType>SENDER</PaymentType>" &_
"<Payor>" &_
"<ResponsibleParty>" &_
"<AccountNumber>700636402</AccountNumber>" &_
"<Contact/>" &_
"</ResponsibleParty>" &_
"</Payor>" &_
"</DutiesPayment>" &_
"<CustomsValue>" &_
"<Currency>UKL</Currency>" &_
"<Amount>0</Amount>" &_
"</CustomsValue>" &_
"<Commodities>" &_
"<NumberOfPieces>1</NumberOfPieces>" &_
"<Description>Test Accessories</Description>" &_
"<CountryOfManufacture>GB</CountryOfManufacture>" &_
"<Weight>" &_
"<Units>KG</Units>" &_
"<Value>10</Value>" &_
"</Weight>" &_
"<Quantity>1</Quantity>" &_
"<QuantityUnits>EA</QuantityUnits>" &_
"<UnitPrice>" &_
"<Currency>UKL</Currency>" &_
"<Amount>0</Amount>" &_
"</UnitPrice>" &_
"</Commodities>" &_
"</CustomsClearanceDetail>" &_
"<LabelSpecification>" &_
"<LabelFormatType>COMMON2D</LabelFormatType>" &_
"<ImageType>PDF</ImageType>" &_
"<LabelStockType>PAPER_LETTER</LabelStockType>" &_
"</LabelSpecification>" &_
"<RateRequestTypes>PREFERRED</RateRequestTypes>" &_
"<PackageCount>1</PackageCount>" &_
"<RequestedPackageLineItems>" &_
"<SequenceNumber>1</SequenceNumber>" &_
"<Weight>" &_
"<Units>KG</Units>" &_
"<Value>10</Value>" &_
"</Weight>" &_
"<CustomerReferences>" &_
"<CustomerReferenceType>CUSTOMER_REFERENCE</CustomerReferenceType>" &_
"<Value>Test Web Services Package 1</Value>" &_
"</CustomerReferences>" &_
"<CustomerReferences>" &_
"<CustomerReferenceType>INVOICE_NUMBER</CustomerReferenceType>" &_
"<Value>Test Web Services Package 1</Value>" &_
"</CustomerReferences>" &_
"</RequestedPackageLineItems>" &_
"</RequestedShipment>" &_
"</ProcessShipmentRequest>" &_
"</soap:Body>" &_
"</soap:Envelope>" &_

oXmlHTTP.send & SOAPRequest 

Response.Write oXmlHTTP.responseText%>

Editing to update with progress.....

I have managed to get the request sent and I can print the entire response. I am trying to write the tracking number but am receiving the error

Microsoft VBScript runtime error '800a01a8'

Object required: '[string: "

/fedex/fedextest2.asp, line 154

Line 54 is

Set nodes = httpRequest.ResponseXML.xml.getElementsByTagName("TrackingNumber")

Full Code now is

<%Dim stringXML, httpRequest, postResponse, XMLResponse

stringXML = "<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soapenv:Envelope xmlns:xsi=""http://fedex.com/ws/ship/v17"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">" &_
"<soapenv:Body>" &_
"<ProcessShipmentRequest xmlns=""http://fedex.com/ws/ship/v17"">" &_
"<WebAuthenticationDetail>" &_
"<UserCredential>" &_
"<Key>1fufGShbz33hZ0ld</Key>" &_
"<Password>3WuWhLQheoF9yoCu9XV851XYn</Password>" &_
"</UserCredential>" &_
"</WebAuthenticationDetail>" &_
"<ClientDetail>" &_
"<AccountNumber>700636402</AccountNumber>" &_
"<MeterNumber>118700937</MeterNumber>" &_
"</ClientDetail>" &_
"<TransactionDetail>" &_
"<CustomerTransactionId>TransactionID_WS1</CustomerTransactionId>" &_
"</TransactionDetail>" &_
"<Version>" &_
"<ServiceId>ship</ServiceId>" &_
"<Major>17</Major>" &_
"<Intermediate>0</Intermediate>" &_
"<Minor>0</Minor>" &_
"</Version>" &_
"<RequestedShipment>" &_
"<ShipTimestamp>2016-02-17T15:56:03</ShipTimestamp>" &_
"<DropoffType>REGULAR_PICKUP</DropoffType>" &_
"<ServiceType>FEDEX_NEXT_DAY_EARLY_MORNING</ServiceType>" &_
"<PackagingType>YOUR_PACKAGING</PackagingType>" &_
"<TotalWeight>" &_
"<Units>KG</Units>" &_
"<Value>10</Value>" &_
"</TotalWeight>" &_
"<Shipper>" &_
"<Contact>" &_
"<PersonName>Paul Cullen</PersonName>" &_
"<CompanyName>Bundle International</CompanyName>" &_
"<PhoneNumber>01782563322</PhoneNumber>" &_
"<EMailAddress>paulcullen@fedex.com</EMailAddress>" &_
"</Contact>" &_
"<Address>" &_
"<StreetLines>Unit 5 Dewar Close</StreetLines>" &_
"<StreetLines>Segensworth West</StreetLines>" &_
"<City>Fareham</City>" &_
"<StateOrProvinceCode/>" &_
"<PostalCode>PO15 5UB</PostalCode>" &_
"<CountryCode>GB</CountryCode>" &_
"</Address>" &_
"</Shipper>" &_
"<Recipient>" &_
"<Contact>" &_
"<PersonName>GDE TEST (POD NEEDED)</PersonName>" &_
"<CompanyName>Joe Bloggs</CompanyName>" &_
"<PhoneNumber>01782563322</PhoneNumber>" &_
"<EMailAddress/>" &_
"</Contact>" &_
"<Address>" &_
"<StreetLines>Parkhouse Industrial Estate</StreetLines>" &_
"<StreetLines/>" &_
"<City>Newcastle Under Lyme</City>" &_
"<StateOrProvinceCode/>" &_
"<PostalCode>ST5 7RB</PostalCode>" &_
"<CountryCode>GB</CountryCode>" &_
"</Address>" &_
"</Recipient>" &_
"<ShippingChargesPayment>" &_
"<PaymentType>SENDER</PaymentType>" &_
"<Payor>" &_
"<ResponsibleParty>" &_
"<AccountNumber>700636402</AccountNumber>" &_
"<Contact/>" &_
"</ResponsibleParty>" &_
"</Payor>" &_
"</ShippingChargesPayment>" &_
"<CustomsClearanceDetail>" &_
"<DutiesPayment>" &_
"<PaymentType>SENDER</PaymentType>" &_
"<Payor>" &_
"<ResponsibleParty>" &_
"<AccountNumber>700636402</AccountNumber>" &_
"<Contact/>" &_
"</ResponsibleParty>" &_
"</Payor>" &_
"</DutiesPayment>" &_
"<CustomsValue>" &_
"<Currency>UKL</Currency>" &_
"<Amount>0</Amount>" &_
"</CustomsValue>" &_
"<Commodities>" &_
"<NumberOfPieces>1</NumberOfPieces>" &_
"<Description>Test Accessories</Description>" &_
"<CountryOfManufacture>GB</CountryOfManufacture>" &_
"<Weight>" &_
"<Units>KG</Units>" &_
"<Value>10</Value>" &_
"</Weight>" &_
"<Quantity>1</Quantity>" &_
"<QuantityUnits>EA</QuantityUnits>" &_
"<UnitPrice>" &_
"<Currency>UKL</Currency>" &_
"<Amount>0</Amount>" &_
"</UnitPrice>" &_
"</Commodities>" &_
"</CustomsClearanceDetail>" &_
"<LabelSpecification>" &_
"<LabelFormatType>COMMON2D</LabelFormatType>" &_
"<ImageType>PDF</ImageType>" &_
"<LabelStockType>PAPER_LETTER</LabelStockType>" &_
"</LabelSpecification>" &_
"<RateRequestTypes>PREFERRED</RateRequestTypes>" &_
"<PackageCount>1</PackageCount>" &_
"<RequestedPackageLineItems>" &_
"<SequenceNumber>1</SequenceNumber>" &_
"<Weight>" &_
"<Units>KG</Units>" &_
"<Value>10</Value>" &_
"</Weight>" &_
"<CustomerReferences>" &_
"<CustomerReferenceType>CUSTOMER_REFERENCE</CustomerReferenceType>" &_
"<Value>Test Web Services Package 1</Value>" &_
"</CustomerReferences>" &_
"<CustomerReferences>" &_
"<CustomerReferenceType>INVOICE_NUMBER</CustomerReferenceType>" &_
"<Value>Test Web Services Package 1</Value>" &_
"</CustomerReferences>" &_
"</RequestedPackageLineItems>" &_
"</RequestedShipment>" &_
"</ProcessShipmentRequest>" &_
"</soapenv:Body>" &_
"</soapenv:Envelope>"

Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
httpRequest.Open "post", "https://wsbeta.fedex.com:443/web-services", False
httpRequest.SetRequestHeader "Content-Type", "text/xml"
httpRequest.setRequestHeader "Content-Length", Len(stringXML)
httpRequest.Send stringXML

If httpRequest.status = 200 Then
  TextResponse = httpRequest.responseText
   'XMLResponse = httpRequest.responseXML
  Call Response.Write(httpRequest.ResponseXML.xml)
  ' StreamResponse = httpRequest.responseStream
  ' response.write(responseStream)
 Set nodes = httpRequest.ResponseXML.xml.getElementsByTagName("TrackingNumber")

For Each node in nodes  
 response.write(node.text)
next 
Else
    ' Handle missing response or other errors here
End If

Set httpRequest = Nothing%>

1 个答案:

答案 0 :(得分:2)

您需要将xml字符串加载到xmldom对象中:

Dim oXMLDoc Set oXMLDoc = CreateObject("Microsoft.XMLDOM") oXMLDoc.loadXML(TextResponse)

现在你可以使用

Set nodes = oXMLDoc.getElementsByTagName("TrackingNumber")