Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 14th, 2006, 03:15 PM
Grant Harmeyer
Guest
 
Posts: n/a
Default UPS Online Tools

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


  #2  
Old March 15th, 2006, 09:35 AM
dickster
Guest
 
Posts: n/a
Default Re: UPS Online Tools

Would it be possible to see the TimeInTransitResponse Class and all the
relevant classes used in the Deserialise process of
TimeInTransitResponse

  #3  
Old April 6th, 2006, 01:25 AM
samstraub
Guest
 
Posts: n/a
Default Re: UPS Online Tools


Grant could you send me your work, I am working on a similar project.
Please let me know and I will pass on my email.



--
samstraub
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles