コード例 #1
0
        //CONSTRUIR XML AUTORIZADO
        private void xmlAutorizado(RespuestaSRI sri, string filename)
        {
            try
            {
                sArchivoFirmar = sDirFirmados + @"\" + txtNumeroDocumento.Text.Trim() + ".xml";

                miXMl = File.ReadAllText(sArchivoFirmar);
                //Declaramos el documento y su definición
                xml = new XDocument(
                    new XDeclaration(sVersion, sUTF, sStandAlone));

                autorizacion = new XElement("autorizacion");
                autorizacion.Add(new XElement("estado", sri.Estado));
                autorizacion.Add(new XElement("numeroAutorizacion", sri.NumeroAutorizacion));
                autorizacion.Add(new XElement("fechaAutorizacion", sri.FechaAutorizacion));
                autorizacion.Add(new XElement("ambiente", sri.Ambiente));
                autorizacion.Add(new XElement("comprobante", new XCData(miXMl)));
                autorizacion.Add(new XElement("mensajes", sri.ErrorMensaje));
                xml.Add(autorizacion);

                //PROBAR COMO GUARDA
                xml.Save(filename);
            }

            catch (Exception ex)
            {
                catchMensaje.LblMensaje.Text = ex.ToString();
                catchMensaje.ShowInTaskbar   = false;
                catchMensaje.ShowDialog();
            }
        }
コード例 #2
0
        /// <summary>
        /// Devuelve la respuesta de la solicitud de recepción del comprobante en una estructura detallada.
        /// </summary>
        /// <param name="xml_doc">Documento XML de respuesta</param>
        public static RespuestaSRI GetRespuestaAutorizacion(XmlDocument xml_doc)
        {
            RespuestaSRI result = new RespuestaSRI();
            string       pathLevelAutorizacion = "RespuestaAutorizacionComprobante/autorizaciones/autorizacion[last()]";
            string       pathLevelMensajes     = "RespuestaAutorizacionComprobante/autorizaciones/autorizacion/mensajes[last()]/mensaje";

            if (result == null)
            {
                return(result);
            }

            result.Estado = GetNodeValue(pathLevelAutorizacion, "estado", xml_doc);

            if (result.Estado == "AUTORIZADO")
            {
                result.Estado             = GetNodeValue(pathLevelAutorizacion, "estado", xml_doc);
                result.NumeroAutorizacion = GetNodeValue(pathLevelAutorizacion, "numeroAutorizacion", xml_doc);
                result.FechaAutorizacion  = GetNodeValue(pathLevelAutorizacion, "fechaAutorizacion", xml_doc);
                result.Ambiente           = GetNodeValue(pathLevelAutorizacion, "ambiente", xml_doc);
                result.Comprobante        = GetNodeValue(pathLevelAutorizacion, "comprobante", xml_doc);
            }
            else if (result.Estado == "NO AUTORIZADO")
            {
                result.Estado             = GetNodeValue(pathLevelAutorizacion, "estado", xml_doc);
                result.FechaAutorizacion  = GetNodeValue(pathLevelAutorizacion, "fechaAutorizacion", xml_doc);
                result.Ambiente           = GetNodeValue(pathLevelAutorizacion, "ambiente", xml_doc);
                result.Comprobante        = GetNodeValue(pathLevelAutorizacion, "comprobante", xml_doc);
                result.ErrorIdentificador = GetNodeValue(pathLevelMensajes, "identificador", xml_doc);
                result.ErrorMensaje       = GetNodeValue(pathLevelMensajes, "mensaje", xml_doc);
                result.ErrorTipo          = GetNodeValue(pathLevelMensajes, "tipo", xml_doc);
            }

            return(result);
        }
コード例 #3
0
        //INSTRUCCIONES PARA FIRMAR EL DOCUMENTO XML
        private bool enviarArchivoXML()
        {
            try
            {
                sArchivoEnviar = sDirFirmados + @"\" + txtNumeroDocumento.Text.Trim() + ".xml";

                if (iIdTipoAmbiente == 1)
                {
                    sWebService = sWSConsultaPruebas;
                }

                else if (iIdTipoAmbiente == 2)
                {
                    sWebService = sWSConsultaProduccion;
                }

                RespuestaSRI respuesta = enviar.EnvioComprobante(sArchivoEnviar, sWebService);

                sEstadoEnvio = respuesta.Estado;

                return(true);
            }

            catch (Exception ex)
            {
                //catchMensaje.LblMensaje.Text = ex.ToString();
                //catchMensaje.ShowDialog();
                return(false);
            }
        }
コード例 #4
0
        //CONSTRUIR XML AUTORIZADO
        private void xmlAutorizado(RespuestaSRI sri, string filename)
        {
            try
            {
                miXMl = File.ReadAllText(sRutaXmlFirmado);
                //Declaramos el documento y su definición
                xml = new XDocument(
                    new XDeclaration(sVersion, sUTF, sStandAlone));

                autorizacion = new XElement("autorizacion");
                autorizacion.Add(new XElement("estado", sri.Estado));
                autorizacion.Add(new XElement("numeroAutorizacion", sri.NumeroAutorizacion));
                autorizacion.Add(new XElement("fechaAutorizacion", sri.FechaAutorizacion));
                autorizacion.Add(new XElement("ambiente", sri.Ambiente));
                autorizacion.Add(new XElement("comprobante", new XCData(sri.Comprobante)));
                autorizacion.Add(new XElement("mensajes", sri.ErrorMensaje));
                xml.Add(autorizacion);

                //PROBAR COMO GUARDA
                xml.Save(filename);
            }

            catch (Exception ex)
            {
                catchMensaje.lblMensaje.Text = ex.ToString();
                catchMensaje.ShowDialog();
            }
        }
コード例 #5
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            try
            {
                //enviarComprobanteSRI();
                bool result = false;

                T_St_ArchivoEnviar = txtRutaArchivosFirmados.Text + @"\" + txtArchivoEnviar.Text;

                NuevoSiNo.lblMensaje.Text = "¿Está seguro de enviar el archivo " + T_St_ArchivoEnviar + "?";
                NuevoSiNo.ShowDialog();

                if (NuevoSiNo.DialogResult != DialogResult.OK)
                {
                    goto fin;
                }

                if ((txtRutaArchivosFirmados.Text.Trim() != "") && (txtNumeroDocumento.Text.Trim() != ""))
                {
                    T_St_Archivo_In  = txtRutaArchivosFirmados.Text + @"\" + txtNumeroDocumento.Text + ".xml";
                    T_St_Archivo_Out = txtRutaArchivosFirmados.Text + @"\" + txtNumeroDocumento.Text + ".txt";
                }

                T_St_Archivobase64 = txtRutaArchivosFirmados.Text + @"\" + txtNumeroDocumento.Text + ".txt";

                if (iIdTipoAmbiente == 1)
                {
                    sWebService = sWSEnvioPruebas;
                }

                else if (iIdTipoAmbiente == 2)
                {
                    sWebService = sWSEnvioProduccion;
                }

                RespuestaSRI respuesta = enviarXML.EnvioComprobante(T_St_Archivo_In, sWebService);

                if (respuesta.Estado == "RECIBIDA")
                {
                    result = true;
                }

                txtEstadoEnvio.Text               = respuesta.Estado;
                txtMensajeErrorEnvio.Text         = respuesta.ErrorMensaje;
                txtCodigoEnvio.Text               = respuesta.ErrorIdentificador;
                txtInformacionAdicionalEnvio.Text = respuesta.ErrorInfoAdicional;
                txtTipoEnvio.Text = respuesta.ErrorTipo;
            }

            catch (Exception ex)
            {
                catchMensaje.lblMensaje.Text = ex.Message;
                catchMensaje.ShowDialog();
            }

            fin : { }
        }
コード例 #6
0
        //ENVIO DE COMPROBANTE AL WEB SERVICE DEL SRI
        /// <summary>
        /// Envía el xml firmado a los webs services del SRI para su recepción.
        /// </summary>
        public RespuestaSRI EnvioComprobante(string sRutaXML, string sWebService_P)
        {
            RespuestaSRI result = null;
            //string ws_url = "https://celcer.sri.gob.ec/comprobantes-electronicos-ws/RecepcionComprobantes?wsdl";
            string ws_url = sWebService_P;

            //Codifica el archivo a base 64
            string bytesEncodeBase64 = ConvertirBase64(sRutaXML);

            //Crea el request del web service
            HttpWebRequest request = CreateWebRequest(ws_url, "POST");

            //Arma la cadena xml ara el envío al web service
            string stringRequest = string.Format(xmlEnvioRequestTemplate, bytesEncodeBase64);

            //Convierte la cadena en un documento xml
            //XmlDocument xmlRequest = ConvertStringToDocument(stringRequest);
            XmlDocument xmlRequest = new XmlDocument();

            xmlRequest.LoadXml(stringRequest);

            //Crea un flujo de datos (stream) y escribe el xml en la solicitud de respuesta del web service
            using (Stream stream = request.GetRequestStream())
            {
                xmlRequest.Save(stream);
            }

            //Obtiene la respuesta del web service
            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    //Lee el flujo de datos (stream) de respuesta del web service
                    string soapResultStr = rd.ReadToEnd();

                    //Convierte la respuesta de string a xml para extraer el detalle de la respuesta del web service
                    //XmlDocument soapResultXML = XMLHelper.ConvertStringToDocument(soapResultStr);
                    //XmlDocument soapResultXML = new XmlDocument();
                    //soapResultXML.LoadXml(soapResultStr);
                    XmlDocument soapResultXML = ConvertStringToDocument(soapResultStr);

                    //Obtiene la respuesta detallada
                    result = ClaseXMLAyuda.GetRespuestaRecepcion(soapResultXML);
                    //result = ClaseEnviarXML.GetRespuestaRecepcion(soapResultXML);
                }
            }

            return(result);
        }
コード例 #7
0
        //INSTRUCCIONES PARA CONSULTAR EL ESTADO DEL XML DEL SRI
        private bool consultarArchivoXML(string sClaveAcceso, int iFila_P)
        {
            try
            {
                sErrorAutorizacion = "";

                if (sClaveAcceso != "")
                {
                    if (sIdTipoAmbiente == "1")
                    {
                        sWebService = sWSEnvioPruebas;
                    }

                    else if (sIdTipoAmbiente == "2")
                    {
                        sWebService = sWSEnvioProduccion;
                    }

                    RespuestaSRI respuesta = consultar.AutorizacionComprobante(out xmlAut, sClaveAcceso, sWebService);
                    sEstadoAutorizacion = respuesta.Estado;
                    sErrorAutorizacion  = respuesta.ErrorMensaje;

                    if (respuesta.Estado == "AUTORIZADO")
                    {
                        dgvDatos.Rows[iFila_P].Cells["colEstado"].Style.BackColor = Color.Lime;
                    }

                    else
                    {
                        dgvDatos.Rows[iFila_P].Cells["colEstado"].Style.BackColor = Color.Red;
                    }

                    return(true);
                }

                else
                {
                    return(false);
                }
            }

            catch (Exception ex)
            {
                //catchMensaje.lblMensaje.Text = ex.ToString();
                //catchMensaje.ShowDialog();
                return(false);
            }
        }
コード例 #8
0
        public static RespuestaSRI GetRespuestaRecepcion(XmlDocument xml_doc)
        {
            RespuestaSRI result = new RespuestaSRI();

            result.Estado = GetNodeValue("RespuestaRecepcionComprobante", "estado", xml_doc);

            if (result.Estado != "RECIBIDA")
            {
                result.ClaveAcceso        = GetNodeValue("comprobante", "claveAcceso", xml_doc);
                result.ErrorIdentificador = GetNodeValue("mensaje", "identificador", xml_doc);
                result.ErrorMensaje       = GetNodeValue("mensaje", "mensaje", xml_doc);
                result.ErrorInfoAdicional = GetNodeValue("mensaje", "informacionAdicional", xml_doc);
                result.ErrorTipo          = GetNodeValue("mensaje", "tipo", xml_doc);
            }

            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Envía la clave de acceso a los webs services del SRI para consultar ele estado de autorización.
        /// </summary>
        public RespuestaSRI AutorizacionComprobante(out XmlDocument xml_doc, string sClaveAcceso, string sWebService_P)
        {
            RespuestaSRI result = null;
            //string ws_url = "https://celcer.sri.gob.ec/comprobantes-electronicos-ws/AutorizacionComprobantes?wsdl";
            string ws_url = sWebService_P;

            //Crea el request del web service
            HttpWebRequest request = CreateWebRequest(ws_url, "POST");

            //Arma la cadena xml para el envío al web service
            string stringRequest = string.Format(xmlAutorizacionRequestTemplate, sClaveAcceso);

            //Convierte la cadena en un documeto xml
            XmlDocument xmlRequest = ConvertStringToDocument(stringRequest);

            xml_doc = xmlRequest;

            //Crea un flujo de datos (stream) y escribe el xml en la solicitud de respuesta del web service
            using (Stream stream = request.GetRequestStream())
            {
                xmlRequest.Save(stream);
            }

            //Obtiene la respuesta del web service
            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    //Lee el flujo de datos (stream) de respuesta del web service
                    string soapResultStr = rd.ReadToEnd();

                    //Convierte la respuesta de string a xml para extraer el detalle de la respuesta del web service
                    XmlDocument soapResultXML = ConvertStringToDocument(soapResultStr);


                    ////PROBAR COMO GUARDA
                    //soapResultXML.Save(@"D:\\FACT.XML");

                    //Obtiene la respuesta detallada
                    result = GetRespuestaAutorizacion(soapResultXML);
                }
            }

            return(result);
        }
コード例 #10
0
        //INSTRUCCIONES PARA CONSULTAR EL ESTADO DEL XML DEL SRI
        private bool consultarArchivoXML()
        {
            try
            {
                sClaveAcceso = consultarClaveAcceso(iIdFactura);
                //txtClaveAcceso.Text = sClaveAcceso;

                if (sClaveAcceso != "")
                {
                    if (iIdTipoAmbiente == 1)
                    {
                        sWebService = sWSConsultaPruebas;
                    }

                    else if (iIdTipoAmbiente == 2)
                    {
                        sWebService = sWSConsultaProduccion;
                    }

                    RespuestaSRI respuesta = consultarXML.AutorizacionComprobante(out xmlAut, sClaveAcceso, sWebService);

                    //dgvDatos.Rows[iFila_P].Cells["colEstado"].Value = respuesta.Estado;
                    sEstadoEnvio        = respuesta.Estado;
                    sNumeroAutorizacion = respuesta.NumeroAutorizacion;
                    sFechaAutorizacion  = respuesta.FechaAutorizacion;

                    //Genera y guarda el XML autorizado
                    filename = Path.GetFileNameWithoutExtension(txtNumeroDocumento.Text.Trim()) + ".xml";

                    if (respuesta.Estado == "AUTORIZADO")
                    {
                        filename = Path.Combine(sDirAutorizados, filename);
                    }

                    else
                    {
                        sDetalleError = respuesta.ErrorMensaje;
//                        dgvDatos.Rows[iFila_P].Cells["colEstado"].Style.BackColor = Color.Red;
                        filename = Path.Combine(sDirNoAutorizados, filename);
                    }


                    xmlAutorizado(respuesta, filename);
                    actualizarDatos();

                    //ENVIAR A FUNCION PARA CREAR EL PDF
                    filename = Path.GetFileNameWithoutExtension(txtNumeroDocumento.Text.Trim()) + ".pdf";
                    filename = Path.Combine(sDirAutorizados, filename);
                    crearRide(filename);

                    return(true);
                }

                else
                {
                    return(false);
                }
            }

            catch (Exception ex)
            {
                //catchMensaje.LblMensaje.Text = ex.ToString();
                //catchMensaje.ShowDialog();
                return(false);
            }
        }
コード例 #11
0
        private void btnValidar_Click(object sender, EventArgs e)
        {
            bool result = false;

            if (!string.IsNullOrWhiteSpace(txtClaveAcceso.Text))
            {
                //wsH.URL_Autorizacion = LblAutorizacion.Text;
                //wsH.ClaveAcceso = TxtClave.Text;

                //Cursor.Current = Cursors.WaitCursor;

                XmlDocument xmlAut;

                try
                {
                    if (iIdTipoAmbiente == 1)
                    {
                        sWebService = sWSConsultaPruebas;
                    }

                    else if (iIdTipoAmbiente == 2)
                    {
                        sWebService = sWSConsultaProduccion;
                    }

                    RespuestaSRI respuesta = consultarXML.AutorizacionComprobante(out xmlAut, txtClaveAcceso.Text, sWebService);
                    //string respuestaStr;

                    txtEstadoEnvio.Text        = respuesta.Estado;
                    txtNumeroAutorizacion.Text = respuesta.NumeroAutorizacion;
                    txtFechaAutorizacion.Text  = respuesta.FechaAutorizacion;
                    txtDetalles_1.Text         = respuesta.ErrorIdentificador;
                    txtDetalles_2.Text         = respuesta.ErrorMensaje + Environment.NewLine + respuesta.ErrorTipo;

                    if ((txtEstadoEnvio.Text == "AUTORIZADO") || (txtEstadoEnvio.Text == "NO AUTORIZADO"))
                    {
                        //Genera y guarda el XML autorizado
                        string filename = Path.GetFileNameWithoutExtension(txtArchivoAutorizado.Text.Trim()) + ".xml";
                        string path     = txtRutaAutorizados.Text;

                        filename = Path.Combine(path, filename);

                        xmlAutorizado(respuesta, filename);

                        actualizarDatos();
                    }
                }
                catch (Exception ex)
                {
                    catchMensaje.lblMensaje.Text = ex.ToString();
                    catchMensaje.ShowDialog();
                    //ClientScript.RegisterClientScriptBlock(GetType(), "mensaje", "alert('Error al usar los web services del SRI 2');", true);
                }
                finally
                {
                    //Cursor.Current = Cursors.Default;
                }
            }

            //return result;
        }