HighTechTalks DotNet Forums  

UPS Online Tools

Dotnet XML microsoft.public.dotnet.xml


Discuss UPS Online Tools in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Grant Harmeyer
 
Posts: n/a

Default UPS Online Tools - 03-09-2006 , 08:53 AM






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



Reply With Quote
  #2  
Old   
dickster
 
Posts: n/a

Default Re: UPS Online Tools - 03-15-2006 , 03:24 AM






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


Reply With Quote
  #3  
Old   
samstraub
 
Posts: n/a

Default Re: UPS Online Tools - 04-05-2006 , 12:44 PM




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
------------------------------------------------------------------------


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.