CODE
class Program
{
static void Main(string[] args)
{
TrackService trackService = new TrackService();
TrackRequest request = new TrackRequest(); // Build a track request object
TrackDetail det = new TrackDetail();
//
request.WebAuthenticationDetail = new WebAuthenticationDetail();
request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
//request.WebAuthenticationDetail.UserCredential.
request.WebAuthenticationDetail.UserCredential.Key = "bgwNo9GWSFah2w66 "; // Replace "XXX" with the Key
request.WebAuthenticationDetail.UserCredential.Password = "Code:39vUaU2DYiIOe78LHq01sVMNl"; // Replace "XXX" with the Password
//
request.ClientDetail = new ClientDetail();
request.ClientDetail.AccountNumber = "510087909"; // Replace "XXX" with clients account number
request.ClientDetail.MeterNumber = "1228702"; // Replace "XXX" with clients meter number
//
request.TransactionDetail = new TransactionDetail();
request.TransactionDetail.CustomerTransactionId = "***Tracking v2 Request using VC#***"; //This is a reference field for the customer. Any value can be used and will be provided in the response.
//
request.Version = new VersionId(); // Creates the Version element with all child elements populated from the wsdl
//
request.PackageIdentifier = new TrackPackageIdentifier(); // Tracking information
request.PackageIdentifier.Value = "0986655645"; // Replace with tracking number or door tag
request.PackageIdentifier.Type = TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG;
//
request.ShipDateRangeBegin = DateTime.Now; // Date range and shippers account number
request.ShipDateRangeEnd = DateTime.Now.AddDays(2);
//
request.Destination = new Address(); // Destination information
request.Destination.City = "Alaska";
request.Destination.StateOrProvinceCode = "AK";
request.Destination.PostalCode = "99504";
request.Destination.CountryCode = "US";
//
// Initialize the service
//
TrackReply reply = trackService.track(request);
try
{
// Console.WriteLine("track details"+trackService.Credentials.ToString() );// This is the call to the web service passing in a request object and returning a reply object
if (reply.HighestSeverity == NotificationSeverityType.SUCCESS) // check if the call was successful
{
Console.WriteLine("Trackinbg details\n");
foreach (TrackDetail trackDetail in reply.TrackDetails) // Track details for each package
{
//Console.WriteLine("Package # {} - Package count {1}", trackDetail.PackageSequenceNumber.ToString().Trim(), trackDetail.PackageCount.ToString());
Console.WriteLine("Package # {} " + trackDetail.PackageCount);
Console.WriteLine("Tracking number {0}", trackDetail.TrackingNumber);
Console.WriteLine("Tracking number unique identifier {0}", trackDetail.TrackingNumberUniqueIdentifier);
Console.WriteLine("Status {0} description {1}", trackDetail.StatusCode, trackDetail.StatusDescription);
if (trackDetail.OtherIdentifiers != null)
{
Console.WriteLine("Other identifiers\n");
foreach (TrackPackageIdentifier identifier in trackDetail.OtherIdentifiers)
{
Console.WriteLine("{0} {1}", identifier.Type, identifier.Value);
}
}
Console.WriteLine("Packaging {0}", trackDetail.Packaging);
Console.WriteLine("Package weight {0} {1}", trackDetail.PackageWeight.Value, trackDetail.PackageWeight.Units);
Console.WriteLine("Shipment weight {0} {1}", trackDetail.ShipmentWeight.Value, trackDetail.ShipmentWeight.Units);
Console.WriteLine("Packaging {0}", trackDetail.Packaging);
Console.WriteLine("Ship date & time", trackDetail.ShipTimestamp);
Console.WriteLine("Destination {0}, {1}, {2}", trackDetail.DestinationAddress.City, trackDetail.DestinationAddress.PostalCode, trackDetail.DestinationAddress.CountryCode);
}
}
else
{
Console.WriteLine(reply.Notifications[0].Message);
}
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerText);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Press any key to quit !");
Console.ReadKey();
}
}