public string ConsumirFindCfdi(DatosBuscarCfdi datos)
        {
            //string apiURL = "http://webapi.factura-electronica-gratis.net.100-42-52-208.hgws28.hgwin.temp.domains/API/FindCfdi";
            string apiURL = "http://localhost:61136/API/FindCfdi";
            string answer = "";

            using (WebClient client = new WebClient())
            {
                //Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
                NameValueCollection myNameValueCollection = new NameValueCollection();

                // Add necessary parameter/value pairs to the name/value container.
                myNameValueCollection.Add("data", datos.JsonDataToString());
                myNameValueCollection.Add("RfcDistribuidor", datos.RfcDistribuidor);
                myNameValueCollection.Add("IdDistribuidor", datos.IdDistribuidor);

                byte[] responsebytes = null;

                try
                {
                    responsebytes = client.UploadValues(apiURL, "POST", myNameValueCollection);
                    answer        = Encoding.UTF8.GetString(responsebytes);
                }
                catch (Exception fault)
                {
                    answer = "Ultima ejecución: " + DateTime.Now + "ocurrió un error al procesar la solicitud: " + fault.Message + " Detalles: " + fault.StackTrace + answer;
                }
            }
            return(answer);
        }
Exemplo n.º 2
0
        protected void BtnFindCfdi_Click(object sender, EventArgs e)
        {
            LblErrorMessage.Text = "";

            DatosBuscarCfdi validaMe = new DatosBuscarCfdi();

            validaMe.RfcDistribuidor = TbxRfcDistribuidor.Text;
            validaMe.IdDistribuidor  = TbxIdDistribuidor.Text;

            validaMe.Version     = TbxVersion.Text;
            validaMe.RfcEmisor   = TbxRfcEmisor.Text;
            validaMe.RfcReceptor = TbxRfcReceptor.Text;
            validaMe.Total       = TbxTotal.Text;
            validaMe.Uuid        = TbxUuid.Text;

            ConsumidorBuscadorCfdi consumidorRest = new ConsumidorBuscadorCfdi();

            //Task<string> answer = null;
            //answer = consumidorRest.ConsumirValidador(validaMe);
            string answerString = consumidorRest.ConsumirFindCfdi(validaMe);



            // TbxResult.Text = answer.Result;
            // TbxResult.Text = answerString;
            LblResult.Text = answerString.Replace(" ", "&nbsp;&nbsp;").Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;").Replace("\r\n", "<br/>").Replace(",", ",<br/>");

            JToken token = null;

            try
            {
                JObject jsonObject = JObject.Parse(answerString);
                token = jsonObject.GetValue("ReportePdf");
            }
            catch (Exception fault)
            {
                // TbxResult.Text = TbxResult.Text + "\r\nEl valor devuelto no se puede interpretar, no es un JSON ";
                LblResult.Text = LblResult.Text + "\r\nEl valor devuelto no se puede interpretar, no es un JSON ";
            }

            if (token != null)
            {
                // JObject thisisme = null;
                LblPdfString.Text = token.Value <string>();
                // LnkDownloadPDF.Visible = true;
            }
            else
            {
                LblPdfString.Text = "";
                // LnkDownloadPDF.Visible = false;
            }
        }