/// <summary> /// Gets all events for a tracking number. /// </summary> /// <param name="trackingNumber">The tracking number to track</param> /// <returns>List of Shipment Events.</returns> public virtual IList<ShipmentStatusEvent> GetShipmentEvents(string trackingNumber) { var result = new List<ShipmentStatusEvent>(); try { //use try-catch to ensure exception won't be thrown is web service is not available var track = new TrackService(); var tr = new TrackRequest(); var upss = new UPSSecurity(); var upssSvcAccessToken = new UPSSecurityServiceAccessToken(); upssSvcAccessToken.AccessLicenseNumber = _upsSettings.AccessKey; upss.ServiceAccessToken = upssSvcAccessToken; var upssUsrNameToken = new UPSSecurityUsernameToken(); upssUsrNameToken.Username = _upsSettings.Username; upssUsrNameToken.Password = _upsSettings.Password; upss.UsernameToken = upssUsrNameToken; track.UPSSecurityValue = upss; var request = new RequestType(); string[] requestOption = { "15" }; request.RequestOption = requestOption; tr.Request = request; tr.InquiryNumber = trackingNumber; System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate { return true; }; var trackResponse = track.ProcessTrack(tr); result.AddRange(trackResponse.Shipment.SelectMany(c => c.Package[0].Activity.Select(x => ToStatusEvent(x))).ToList()); } catch (SoapException ex) { var sb = new StringBuilder(); sb.AppendFormat("SoapException Message= {0}.", ex.Message); sb.AppendFormat("SoapException Category:Code:Message= {0}.", ex.Detail.LastChild.InnerText); //sb.AppendFormat("SoapException XML String for all= {0}.", ex.Detail.LastChild.OuterXml); _logger.Error(string.Format("Error while getting UPS shipment tracking info - {0}", trackingNumber), new Exception(sb.ToString())); } catch (Exception exc) { _logger.Error(string.Format("Error while getting UPS shipment tracking info - {0}", trackingNumber), exc); } return result; }
/// <remarks/> public void ProcessTrackAsync(TrackRequest TrackRequest) { this.ProcessTrackAsync(TrackRequest, null); }
/// <remarks/> public void ProcessTrackAsync(TrackRequest TrackRequest, object userState) { if ((this.ProcessTrackOperationCompleted == null)) { this.ProcessTrackOperationCompleted = new System.Threading.SendOrPostCallback(this.OnProcessTrackOperationCompleted); } this.InvokeAsync("ProcessTrack", new object[] { TrackRequest}, this.ProcessTrackOperationCompleted, userState); }