I have some code that generates XML output.
The header should look like this:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://fedex.com/ws/rate/v31">
However, my code is outputting this:
<SOAP-ENV:Envelope
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://fedex.com/ws/rate/v31"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
For some reason, the xmlns:SOAP-ENV
is at the end instead of the beginning. Not sure why.
The code:
Using Request As XmlWriter = XmlWriter.Create(RequestXMLString)
'Start ConfirmRequest Document
Request.WriteStartDocument(False)
Request.WriteStartElement("SOAP-ENV", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/")
Request.WriteAttributeString("xmlns", "SOAP-ENC", Nothing, "http://schemas.xmlsoap.org/soap/encoding/")
Request.WriteAttributeString("xmlns", "xsi", Nothing, "http://www.w3.org/2001/XMLSchema-instance")
Request.WriteAttributeString("xmlns", "xsd", Nothing, "http://www.w3.org/2001/XMLSchema")
Request.WriteAttributeString("xmlns", "", Nothing, "http://fedex.com/ws/rate/v31")
Request.WriteStartElement("Body", "http://schemas.xmlsoap.org/soap/envelope/")
'...rest of code...
Full SOAP output:
<?xml version="1.0" encoding="utf-16" standalone="no"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://fedex.com/ws/rate/v31"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<RateRequest>
<WebAuthenticationDetail>
<ParentCredential>
<Key>KEY</Key>
<Password>PASSWORD</Password>
</ParentCredential>
<UserCredential>
<Key>KEY</Key>
<Password>PASSWORD</Password>
</UserCredential>
</WebAuthenticationDetail>
<ClientDetail>
<AccountNumber>ACCTNUM</AccountNumber>
<MeterNumber>METERNUM</MeterNumber>
<SoftwareId>WSXI</SoftwareId>
</ClientDetail>
<TransactionDetail>
<CustomerTransactionId>ID</CustomerTransactionId>
</TransactionDetail>
<Version>
<ServiceId>crs</ServiceId>
<Major>31</Major>
<Intermediate>0</Intermediate>
<Minor>0</Minor>
</Version>
<RequestedShipment>
<ShipTimestamp>2/7/2022 10:57:05 AM</ShipTimestamp>
<DropoffType>REGULAR_PICKUP</DropoffType>
<ServiceType>FEDEX_GROUND</ServiceType>
<PackagingType>FEDEX_BOX</PackagingType>
<Shipper>
<AccountNumber>ACCTNUM</AccountNumber>
<Contact>
<CompanyName>COMPANYNAME</CompanyName>
<PhoneNumber>111-111-1111</PhoneNumber>
</Contact>
<Address>
<StreetLines>ADDRESS1</StreetLines>
<StreetLines>ADDRESS2</StreetLines>
<City>CITY</City>
<StateOrProvinceCode>ZZ</StateOrProvinceCode>
<PostalCode>11111</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Shipper>
<Recipient>
<AccountNumber>ACCTNUM</AccountNumber>
<Contact>
<PersonName>DUDE</PersonName>
<PhoneNumber>111-111-1111</PhoneNumber>
</Contact>
<Address>
<StreetLines>ADDRESS1</StreetLines>
<City>CITY</City>
<StateOrProvinceCode>ZZ</StateOrProvinceCode>
<PostalCode>11111-0000</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</Recipient>
<ShippingChargesPayment>
<PaymentType>SENDER</PaymentType>
<Payor>
<ResponsibleParty>
<AccountNumber>ACCTNUM</AccountNumber>
<Tins>
<TinType>BUSINESS_STATE</TinType>
<Number>123456</Number>
</Tins>
</ResponsibleParty>
</Payor>
</ShippingChargesPayment>
<RateRequestTypes>LIST</RateRequestTypes>
<PackageCount>1</PackageCount>
<RequestedPackageLineItems>
<SequenceNumber>1</SequenceNumber>
<GroupNumber>1</GroupNumber>
<GroupPackageCount>1</GroupPackageCount>
<Weight>
<Units>LB</Units>
<Value>1.05</Value>
</Weight>
<Dimensions>
<Length>12</Length>
<Width>12</Width>
<Height>12</Height>
<Units>IN</Units>
</Dimensions>
<ContentRecords>
<PartNumber>123456</PartNumber>
<ItemNumber>ITEMNUM</ItemNumber>
<ReceivedQuantity>12</ReceivedQuantity>
<Description>ContentDescription</Description>
</ContentRecords>
</RequestedPackageLineItems>
</RequestedShipment>
</RateRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The section of code that deals with sending the request:
Dim RequestOutput As String = RequestXMLString.ToString()
Dim HttpRequest As String = RequestOutput
Dim XMLVar As String = ""
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim FedexRequest As HttpWebRequest = DirectCast(WebRequest.Create("https://ws.fedex.com:443/web-services"), HttpWebRequest)
Dim buffer As Byte() = Encoding.ASCII.GetBytes(HttpRequest)
FedexRequest.Credentials = CredentialCache.DefaultCredentials
FedexRequest.Method = "POST"
FedexRequest.ContentType = "application/x-www-form-urlencoded"
FedexRequest.ContentLength = buffer.Length
Dim receiveStream As Stream = FedexRequest.GetRequestStream()
receiveStream.Write(buffer, 0, buffer.Length)
receiveStream.Close()
Dim UPSResponse As HttpWebResponse = DirectCast(FedexRequest.GetResponse, HttpWebResponse) 'Error occurs here
Dim answerStream As Stream = UPSResponse.GetResponseStream()
Dim _answerStream As StreamReader = New StreamReader(answerStream)
XMLVar = _answerStream.ReadToEnd().ToString
ThisForm.Variables("XMLVar").Value = XMLVar