Пример #1
0
        private static ShipServiceResponse ShowShipmentReply(bool isCodShipment, ProcessShipmentReply reply, ShipServiceInfo clsService, ShipServiceResponse objResponse, out string retVal)
        {
            //F21.Service.ShipServiceResponse objResponse = new F21.Service.ShipServiceResponse();
            retVal = string.Empty;

            try
            {
                // Carrier code types : FDXC(Cargo), FDXE(Express), FDXG(Ground), FXCC(Custom Critical), FXFX(Freight), FXSP - ? (Reference FedEx Document)
                // SmartPost Reply details
                if (clsService.ServiceType == ServiceType.SMART_POST)
                {
                    if (reply.CompletedShipmentDetail.SmartPostDetail.PickUpCarrierSpecified)
                    {
                        objResponse.SmartPickupCode = reply.CompletedShipmentDetail.SmartPostDetail.PickUpCarrier.ToString();
                    }

                    if (reply.CompletedShipmentDetail.SmartPostDetail.MachinableSpecified)
                    {
                        objResponse.SmartMachinable = reply.CompletedShipmentDetail.SmartPostDetail.Machinable;
                    }
                }

                // Details for each package
                if (reply.CompletedShipmentDetail.CompletedPackageDetails != null)
                {
                    System.Diagnostics.Debug.WriteLine("CompletedPackageDetails Array Length : " + reply.CompletedShipmentDetail.CompletedPackageDetails.Length);
                    foreach (CompletedPackageDetail packageDetail in reply.CompletedShipmentDetail.CompletedPackageDetails)
                    {
                        //Get Fedex TrackingNumber  (ShowTrackingDetails)
                        if (packageDetail.TrackingIds != null)
                        {
                            System.Diagnostics.Debug.WriteLine("TrackingIds Array Length : " + packageDetail.TrackingIds.Length);
                            for (int i = 0; i < packageDetail.TrackingIds.Length; i++)
                            {
                                // TrackingIdType (EXPRESS,FEDEX,FREIGHT,GROUND,USPS)
                                // Update ShipService version from v15 to v17
                                objResponse.TrackingIdType      = packageDetail.TrackingIds[i].TrackingIdType.ToString();
                                objResponse.FedexTrackingNumber = packageDetail.TrackingIds[i].TrackingNumber;
                                objResponse.FormId            = packageDetail.TrackingIds[i].FormId;
                                objResponse.UspsApplicationId = Basic.IsNull(packageDetail.TrackingIds[i].UspsApplicationId, "");

                                /*  (Comment out the below sourcecode)
                                 * if (packageDetail.TrackingIds[i].TrackingIdType == TrackingIdType.USPS)
                                 * {
                                 *  objResponse.USPSTrackingIdType = packageDetail.TrackingIds[i].TrackingIdType.ToString();
                                 *  objResponse.USPSTrackingNumber = packageDetail.TrackingIds[i].TrackingNumber;
                                 *  objResponse.USPSFormId = packageDetail.TrackingIds[i].FormId;
                                 * }
                                 * else
                                 * {
                                 *  objResponse.TrackingIdType = packageDetail.TrackingIds[i].TrackingIdType.ToString();
                                 *  objResponse.FedexTrackingNumber = packageDetail.TrackingIds[i].TrackingNumber;
                                 *  objResponse.FormId = packageDetail.TrackingIds[i].FormId;
                                 * }
                                 */
                            }
                        }
                        else
                        {
                            // Tracking Number Issue
                            retVal = "[ERROR] packageDetail.TrackingIds is null.";
                        }

                        //Get LabelString (ShowShipmentLabels)
                        if (packageDetail.Label.Parts != null)
                        {
                            if (clsService.LabelImageType == ShippingDocumentImageType.ZPLII)
                            {
                                // Get ZPL Label Strig
                                objResponse.FedexLabelString = ShowShipmentLabels(packageDetail);
                            }
                            else if (clsService.LabelImageType == ShippingDocumentImageType.PDF)
                            {
                                objResponse.FedexLabelString = ShowShipmentLabels3(isCodShipment, reply.CompletedShipmentDetail, packageDetail);
                            }
                            else
                            {
                                objResponse.FedexLabelString = ShowShipmentLabels(packageDetail);
                            }
                        }
                        else
                        {
                            retVal = retVal + " [ERROR] packageDetail.Label.Parts is null.";
                        }

                        // *** Check functon (ShowPackageRateDetails) Don't use package rate detalis information
                        // PackageRateDetails 에러가 종종 발생하기 때문에 주석 처리, TrackingNumber, ZplString Value 가 존재하면 정상 처리함.

                        /* (Comment out the below sourcecode)
                         * if (packageDetail.PackageRating.PackageRateDetails != null)
                         * {
                         *  System.Diagnostics.Debug.WriteLine("PackageRateDetails Array Length :" + packageDetail.PackageRating.PackageRateDetails.Length);
                         *  foreach (PackageRateDetail ratedPackage in packageDetail.PackageRating.PackageRateDetails)
                         *  {
                         *      System.Diagnostics.Debug.WriteLine("Billing weight :" + ratedPackage.BillingWeight.Value.ToString());
                         *      System.Diagnostics.Debug.WriteLine("Billing weight Units :" + ratedPackage.BillingWeight.Units.ToString());
                         *
                         *      objResponse.BillingWeight = ratedPackage.BillingWeight.Value;
                         *      objResponse.BillingWeightUnits = ratedPackage.BillingWeight.Units.ToString();
                         *
                         *      System.Diagnostics.Debug.WriteLine("Base charge : " + ratedPackage.BaseCharge.Amount + "-" + ratedPackage.BaseCharge.Currency);
                         *      System.Diagnostics.Debug.WriteLine("Total surcharge : " + ratedPackage.TotalSurcharges.Amount + "-" + ratedPackage.TotalSurcharges.Currency);
                         *
                         *      if (ratedPackage.Surcharges != null)
                         *      {
                         *          foreach (Surcharge surcharge in ratedPackage.Surcharges)
                         *          {
                         *              System.Diagnostics.Debug.WriteLine("Surcharge : " + surcharge.SurchargeType + " - " + surcharge.Amount.Amount + " - " + surcharge.Amount.Currency);
                         *          }
                         *      }
                         *
                         *      if (ratedPackage.NetCharge != null)
                         *      {
                         *          System.Diagnostics.Debug.WriteLine("Net charge : " + ratedPackage.NetCharge.Amount + "-" + ratedPackage.NetCharge.Currency);
                         *      }
                         *  }
                         * }
                         */
                        //---------------------------------------------------------------------------------------------------------------------------------------

                        // Get Barcode (ShowBarcodeDetails)
                        if (packageDetail.OperationalDetail.Barcodes != null)
                        {
                            if (packageDetail.OperationalDetail.Barcodes.StringBarcodes != null)
                            {
                                System.Diagnostics.Debug.WriteLine("StringBarcodes Array Length :" + packageDetail.OperationalDetail.Barcodes.StringBarcodes.Length);
                                for (int i = 0; i < packageDetail.OperationalDetail.Barcodes.StringBarcodes.Length; i++)
                                {
                                    //List<string> list = new List<string>();

                                    // String Barcode Types : ADDRESS, ASTRA, FEDEX_1D, GROUND, POSTAL,USPS
                                    // Update ShipService version from v15 to v17
                                    objResponse.Barcode     = packageDetail.OperationalDetail.Barcodes.StringBarcodes[i].Value;
                                    objResponse.BarcodeType = packageDetail.OperationalDetail.Barcodes.StringBarcodes[i].Type.ToString();

                                    /* (Comment out the below sourcecode)
                                     * if (packageDetail.OperationalDetail.Barcodes.StringBarcodes[i].Type == StringBarcodeType.USPS)
                                     * {
                                     *  objResponse.USPSBarcode = packageDetail.OperationalDetail.Barcodes.StringBarcodes[i].Value;
                                     *  objResponse.USPSBarcodeType = packageDetail.OperationalDetail.Barcodes.StringBarcodes[i].Type.ToString();
                                     * }
                                     * else
                                     * {
                                     *  objResponse.Barcode = packageDetail.OperationalDetail.Barcodes.StringBarcodes[i].Value;
                                     *  objResponse.BarcodeType = packageDetail.OperationalDetail.Barcodes.StringBarcodes[i].Type.ToString();
                                     * }
                                     */
                                    //Object reference not set to an instance of an object.
                                    //objResponse.ResponseStringBarcodes[i] = packageDetail.OperationalDetail.Barcodes.StringBarcodes[i].Value;
                                }
                            }

                            // Don't use BinaryBarcodes (Comment out the BinaryBarcodes sourcecode)

                            /*
                             * if (packageDetail.OperationalDetail.Barcodes.BinaryBarcodes != null)
                             * {
                             *  System.Diagnostics.Debug.WriteLine("BinaryBarcodes Array Length :" + packageDetail.OperationalDetail.Barcodes.BinaryBarcodes.Length);
                             *  for (int i = 0; i < packageDetail.OperationalDetail.Barcodes.BinaryBarcodes.Length; i++)
                             *  {
                             *      objResponse.BinaryBarcodeType = packageDetail.OperationalDetail.Barcodes.BinaryBarcodes[i].Type.ToString();
                             *  }
                             * }
                             */
                        }
                    }
                }

                // ShowPackageRouteDetails
                if (reply.CompletedShipmentDetail.OperationalDetail != null)
                {
                    ShipmentOperationalDetail routingDetail = reply.CompletedShipmentDetail.OperationalDetail;
                    objResponse.UrsaPrefixCode        = routingDetail.UrsaPrefixCode;
                    objResponse.UrsaSuffixCode        = routingDetail.UrsaSuffixCode;
                    objResponse.DestinationLocationId = routingDetail.DestinationLocationId;
                    objResponse.AirportId             = routingDetail.AirportId;


                    if (routingDetail.TransitTimeSpecified)
                    {
                        objResponse.TransitTime = routingDetail.TransitTime.ToString();
                    }

                    /*
                     * if (routingDetail.DeliveryDaySpecified)
                     * {
                     *  string DeliveryDay = routingDetail.DeliveryDay.ToString();
                     * }
                     *
                     * if (routingDetail.DeliveryDateSpecified)
                     * {
                     *  string DeliveryShortDate = routingDetail.DeliveryDate.ToShortDateString();
                     * }
                     */

                    //throw new Exception("Test Error");
                }
            }
            catch (Exception ex)
            {
                retVal = retVal + "[ShowShipmentReply Error] " + ex.Message;
            }

            return(objResponse);
        }
Пример #2
0
        public ShipServiceResponse ShipClientService(ShipServiceInfo clsService, AddressInfo clsAddress)
        {
            FedExWebServiceClient.ShipServiceWebReference.ShipService service = new FedExWebServiceClient.ShipServiceWebReference.ShipService();
            ShipServiceResponse shipResponse = new ShipServiceResponse();

            string iResultCode    = string.Empty;
            string iResultMessage = string.Empty;
            string iErrorMessage  = string.Empty;
            string retValue       = string.Empty;
            string strApiUrl      = string.Empty;

            string noticeCode     = string.Empty;
            string noticeMessage  = string.Empty;
            string noticeSeverity = string.Empty;
            string noticeSource   = string.Empty;


            // WebService Url Setting
            retValue = GetWebserviceUrl(out strApiUrl);
            if (!string.IsNullOrEmpty(retValue))
            {
                shipResponse.isSuccess    = false;
                shipResponse.ErrorMessage = "[ERROR] Ship Webservice url is empty.\r\n  Error Message : " + retValue;

                return(shipResponse);
            }

            try
            {
                bool isCodShipment = clsService.IsCOD; // Don't use cash on delivery in US.

                // Create Shipment Request
                ProcessShipmentRequest request = CreateShipmentRequest(clsService, clsAddress, isCodShipment);

                // Webservice URL
                service.Url = strApiUrl;

                // Call the ship web service passing in a ProcessShipmentRequest and returning a ProcessShipmentReply

                System.Diagnostics.Debug.WriteLine(Encoding.Default.GetString(serializeToSoap(request)));

                ProcessShipmentReply reply = service.processShipment(request);

                // Call ShowNotifications(reply)
                NameValueCollection nvcNotification = ShowNotifications(reply, out iResultMessage);
                foreach (string nvKey in nvcNotification.AllKeys)
                {
                    switch (nvKey)
                    {
                    case "Code":
                        shipResponse.NoticeCode = nvcNotification[nvKey].ToString();
                        break;

                    case "Message":
                        shipResponse.NoticeMessage = nvcNotification[nvKey].ToString();
                        break;

                    case "Severity":
                        shipResponse.NoticeSeverity = nvcNotification[nvKey].ToString();
                        break;

                    case "Source":
                        shipResponse.NoticeSource = nvcNotification[nvKey].ToString();
                        break;

                    default:
                        break;
                    }
                }

                // SUCCESS, NOTE, WARNING
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    shipResponse.HighestSeverity = reply.HighestSeverity.ToString();

                    //retVal = ShowNotifications(reply, out iResultCode, out iResultMessage);
                    // Call ShowNotifications(reply)

                    shipResponse = ShowShipmentReply(isCodShipment, reply, clsService, shipResponse, out retValue);

                    //shipResponse.ResultCode = iResultCode;
                    //shipResponse.ResultMessage = iResultMessage;

                    if (retValue.Equals(string.Empty))
                    {
                        shipResponse.isSuccess = true;
                    }
                    else
                    {
                        // Check FedexTrackingNumber (If Smart_Post service type)
                        if (!string.IsNullOrEmpty(shipResponse.FedexTrackingNumber) && !string.IsNullOrEmpty(shipResponse.FedexLabelString))
                        {
                            shipResponse.isSuccess = true;  // if exists Tracking number and Label string.
                        }
                        else
                        {
                            shipResponse.isSuccess = false;
                        }

                        shipResponse.ErrorMessage = "[ShowShipmentReply Error] " + retValue;
                    }
                }
                else // ERROR, FAILURE
                {
                    shipResponse.HighestSeverity = Basic.IsNull(reply.HighestSeverity.ToString(), "Empty");

                    shipResponse.isSuccess    = false;
                    shipResponse.ErrorMessage = "[" + shipResponse.HighestSeverity + "] Notification Code: " + shipResponse.NoticeCode + ",\r\nNotification Message: " + shipResponse.NoticeMessage;

                    //retVal = ShowNotifications(reply, out iResultMessage);

                    //if (retVal == "")
                    //{
                    //    shipResponse.ResultCode = iResultCode;
                    //    shipResponse.ResultMessage = iResultMessage;

                    //    shipResponse.isSuccess = false;
                    //    shipResponse.ErrorMessage = "[" + shipResponse.HighestSeverity + "] ResultCode: " + shipResponse.NoticeCode + ", ResultMsg: " + shipResponse.NoticeMessage;
                    //}
                    //else
                    //{
                    //    shipResponse.isSuccess = false;
                    //    shipResponse.ErrorMessage = retVal;
                    //}
                }

                //shipResponse.NoticeCode = noticeCode;
                //shipResponse.NoticeMessage = noticeMessage;
                //shipResponse.NoticeSeverity = noticeSeverity;
                //shipResponse.NoticeSource = noticeSource;
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw ex;
            }
            catch (System.ServiceModel.CommunicationException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (service != null)
                {
                    service.Dispose();
                }
            }

            return(shipResponse);
        }