/// <summary>
        /// Returns decoded pdf file
        /// </summary>
        /// <param name="shipmentNumber"></param>
        /// <param name="printerName"></param>
        /// <returns></returns>
        public byte[] PrintLabel(string shipmentNumber)
        {
            shippingAPIPortTypeClient client = GetProxy();
            var request = new printLabelRequest();

            request.integrationHeader = GetIntegrationHeader();
            request.shipmentNumber    = shipmentNumber;
            request.outputFormat      = "PDF";

            // http://stackoverflow.com/questions/897782/how-to-add-custom-http-header-for-c-sharp-web-service-client-consuming-axis-1-4
            //XmlHelper.Serialise<createShipmentRequest>(request, @"C:\test\createShipmentRequest.xml");
            using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
            {
                var httpRequestProperty = new HttpRequestMessageProperty();
                httpRequestProperty.Headers.Add(@"X-IBM-Client-Id", _credentials.HttpSecurity.ClientId);
                httpRequestProperty.Headers.Add(@"X-IBM-Client-Secret", _credentials.HttpSecurity.ClientSecret);
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

                printLabelResponse response = client.printLabel(GetSecurityHeaderType(), request);

                CheckErrorsAndWarnings(response.integrationFooter);
                var labelBytes = response.label;
                return(labelBytes);
            }
        }
Exemple #2
0
        public async Task <ActionResult> printLabel([FromBody]  printLabelRequest printLabelRequest)
        {
            try
            {
                var items = await(from o in db.TbtOrder
                                  where printLabelRequest.DocNums.Contains(o.DocNum)
                                  select o).ToListAsync();
                List <LabelItem> labelItems = new List <LabelItem>();
                items.ForEach(x =>
                {
                    LabelItem l = new LabelItem
                    {
                        Dscription = x.Dscription,
                        Quantity   = x.Quantity,
                    };
                    labelItems.Add(l);
                });
                LabelDocumentModel labelDocumentModel = new LabelDocumentModel
                {
                    Address    = items.FirstOrDefault().Address,
                    CardName   = items.FirstOrDefault().CardName,
                    DocDate    = items.FirstOrDefault().DocDate,
                    DocDueDate = items.FirstOrDefault().DocDueDate,
                    DocNum     = string.Join(",", printLabelRequest.DocNums.ToArray()),
                    labelItems = labelItems,
                    Remark     = items.FirstOrDefault().Remark
                };


                LabelDocument pDoc = new LabelDocument(this._hostingEnvironment);

                Stream resultPDFStream = pDoc.CreatePDF(labelDocumentModel);
                resultPDFStream.Position = 0;
                if (resultPDFStream.Length != 0)
                {
                    FileStreamResult fileStreamResult = new FileStreamResult(resultPDFStream, "application/pdf");
                    fileStreamResult.FileDownloadName = "label_" + "" + ".pdf";


                    return(fileStreamResult);
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }