OK, this is going to be a lengthy post with a lot of code. I have built a
class library in C# for communicating with UPS' online tools for package
tracking, time in transit and a few other services. I have used
serialization to form the requests and I use deserialization to read the
responses. The code for Rates and Services works beautifully but the Time in
transit deserialization states that there is no root element in the XML that
UPS kicks back. The deserialization method for the response was copied from
the working Rates and Rervices response with the only modification being the
type passed to the XmlSerializer constructor. Any Ideas? code listed below:
XML Request from Serialized object(s):
--------------------------------------
<?xml version="1.0" encoding="utf-16"?>
<AccessRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en-US">
<AccessLicenseNumber>9BE571A78CC539A8</AccessLicenseNumber>
<UserId>ApolloDesignTech</UserId>
<Password>upsgbjyd</Password>
</AccessRequest>
<?xml version="1.0" encoding="utf-16"?>
<TimeInTransitRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en-US">
<Request>
<TransactionReference>
<CustomerContext>TNT_D Origin Country Code</CustomerContext>
<XpciVersion>1.0002</XpciVersion>
</TransactionReference>
<RequestAction>TimeInTransit</RequestAction>
<RequestOption />
</Request>
<TransitFrom>
<AddressArtifactFormat>
<PoliticalDivision2>LONDON</PoliticalDivision2>
<PoliticalDivision1>CITY OF LONDON</PoliticalDivision1>
<Country />
<CountryCode>GB</CountryCode>
<PostcodePrimaryLow>EC03</PostcodePrimaryLow>
</AddressArtifactFormat>
</TransitFrom>
<TransitTo>
<AddressArtifactFormat>
<PoliticalDivision2>NASSAU</PoliticalDivision2>
<PoliticalDivision1 />
<Country />
<CountryCode>BS</CountryCode>
<PostcodePrimaryLow />
</AddressArtifactFormat>
</TransitTo>
<ShipmentWeight>
<UnitOfMeasurement>
<Code>KGS</Code>
<Description>Kilograms</Description>
</UnitOfMeasurement>
<Weight>23</Weight>
</ShipmentWeight>
<TotalPackagesInShipment>123</TotalPackagesInShipment>
<InvoiceLineTotal>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>250</MonetaryValue>
</InvoiceLineTotal>
<PickupDate>20060309</PickupDate>
<DocumentsOnlyIndicator />
</TimeInTransitRequest>
Raw XML Response from UPS.com
--------------------------------------
<?xml version="1.0"?>
<TimeInTransitResponse>
<Response>
<TransactionReference>
<CustomerContext>TNT_D Origin Country Code</CustomerContext>
<XpciVersion>1.0002</XpciVersion>
</TransactionReference>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusDescription>Success</ResponseStatusDescription>
</Response>
<TransitResponse>
<PickupDate>2006-03-15</PickupDate>
<TransitFrom>
<AddressArtifactFormat>
<PoliticalDivision2>LONDON</PoliticalDivision2>
<PoliticalDivision1>CITY OF LONDON</PoliticalDivision1>
<Country>UNITED KINGDOM</Country>
<CountryCode>GB</CountryCode>
<PostcodePrimaryLow>EC03</PostcodePrimaryLow>
</AddressArtifactFormat>
</TransitFrom>
<TransitTo>
<AddressArtifactFormat>
<PoliticalDivision2>NASSAU</PoliticalDivision2>
<Country>BAHAMAS</Country>
<CountryCode>BS</CountryCode>
</AddressArtifactFormat>
</TransitTo>
<DocumentsOnlyIndicator></DocumentsOnlyIndicator>
<AutoDutyCode>02</AutoDutyCode>
<ShipmentWeight>
<UnitOfMeasurement>
<Code>KGS</Code>
</UnitOfMeasurement>
<Weight>0.2</Weight>
</ShipmentWeight>
<InvoiceLineTotal>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>250.00</MonetaryValue>
</InvoiceLineTotal>
<Disclaimer>Services listed as guaranteed are backed by a money-back
guarantee for transportation charges only. See Terms and Conditions in the
Service Guide for details. Certain commodities and high value shipments may
require additional transit time for customs clearance.</Disclaimer>
<ServiceSummary>
<Service>
<Code>11</Code>
<Description>UPS Express NA1</Description>
</Service>
<Guaranteed>
<Code>Y</Code>
</Guaranteed>
<EstimatedArrival>
<BusinessTransitDays>1</BusinessTransitDays>
<Time>23:30:00</Time>
<PickupDate>2006-03-15</PickupDate>
<PickupTime>16:00:00</PickupTime>
<HolidayCount>0</HolidayCount>
<DelayCount>0</DelayCount>
<Date>2006-03-16</Date>
<DayOfWeek>THU</DayOfWeek>
<TotalTransitDays>1</TotalTransitDays>
<CustomerCenterCutoff>15:00:00</CustomerCenterCutoff>
<RestDays>0</RestDays>
</EstimatedArrival>
</ServiceSummary>
<ServiceSummary>
<Service>
<Code>01</Code>
<Description>UPS Worldwide Express</Description>
</Service>
<Guaranteed>
<Code>Y</Code>
</Guaranteed>
<EstimatedArrival>
<BusinessTransitDays>2</BusinessTransitDays>
<Time>23:30:00</Time>
<PickupDate>2006-03-15</PickupDate>
<PickupTime>19:00:00</PickupTime>
<HolidayCount>0</HolidayCount>
<DelayCount>0</DelayCount>
<Date>2006-03-17</Date>
<DayOfWeek>FRI</DayOfWeek>
<TotalTransitDays>2</TotalTransitDays>
<CustomerCenterCutoff>18:30:00</CustomerCenterCutoff>
<RestDays>0</RestDays>
</EstimatedArrival>
</ServiceSummary>
<MaximumListSize>35</MaximumListSize>
</TransitResponse>
</TimeInTransitResponse>
Deserialization Method of the TimeInTransitResponse object
--------------------------------------
public void Deserialize ( System.IO.Stream xmlResponseStream )
{
// Local Variables
TimeInTransitResponse r = null;
XmlSerializer xs = new XmlSerializer(typeof(TimeInTransitResponse));
// Begin
try
{
r = new TimeInTransitResponse();
r = (TimeInTransitResponse) xs.Deserialize(xmlResponseStream);
this.Response = r.Response;
this.TransitResponse = r.TransitResponse;
}// end try
catch ( Exception appEx )
{
this.DeserializeException = appEx;
}// end catch
finally
{
xmlResponseStream.Close();
}// end finally
}// end Deserialize
Exception:
--------------------------------------
System.InvalidOperationException: There is an error in XML document (0,
0). ---> System.Xml.XmlException: The root element is missing.
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.MoveToContent()
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read13_TimeInTransitResponse()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize (Stream stream)
at
ApolloDesignTechnology.Shipping.Ups.TimeInTransit. TimeInTransitResponse.Deserialize(Stream
xmlResponseStream)
--
Grant Harmeyer