コード例 #1
0
        /// <summary>
        /// Funcion que se encarga de realizar el timbrado de una facturacion dandole el nombre del archivo xml que se timbrara
        /// </summary>
        /// <param name="nameFile">variable de tipo string</param>
        public static void timbrado(string nameFile)
        {
            try
            {
                /* Consumir web service de timbrado */
                StampSOAP     selloSOAP            = new StampSOAP();
                stamp         oStamp               = new stamp();
                stampResponse selloResponse        = new stampResponse();
                Incidencia    incidencia           = new Incidencia();
                string        MESPATH              = @"C:\SiscomSoft\Facturas\XML\" + DateTime.Now.ToString("MMMM") + "," + DateTime.Now.Year;
                string        NameWithoutExtension = Path.GetFileNameWithoutExtension(MESPATH + @"\" + nameFile);

                //Cargas tu archivo xml
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(MESPATH + @"\" + nameFile);

                //Conviertes el archivo en byte
                byte[] byteXmlDocument = Encoding.UTF8.GetBytes(xmlDocument.OuterXml);
                //Conviertes el byte resultado en base64
                string stringByteXmlDocument = Convert.ToBase64String(byteXmlDocument);
                //Convirtes el resultado nuevamente a byte
                byteXmlDocument = Convert.FromBase64String(stringByteXmlDocument);

                //Timbras el archivo
                oStamp.xml      = byteXmlDocument;
                oStamp.username = "******";
                oStamp.password = "******";

                //Recibes la respuesta de timbrado
                selloResponse = selloSOAP.stamp(oStamp);
                /* Consumir web service de timbrado */

                if (selloResponse.stampResult.Incidencias != null)
                {
                    StreamWriter error = new StreamWriter(@"C:\SiscomSoft\Facturas\Errors\ERROR_" + NameWithoutExtension + ".log.txt");
                    error.WriteLine("CODIGO ERROR       " + "MENSAJE DE ERROR");
                    for (int i = 0; i < selloResponse.stampResult.Incidencias.Count(); i++)
                    {
                        error.WriteLine(selloResponse.stampResult.Incidencias[i].CodigoError + "                " + selloResponse.stampResult.Incidencias[i].MensajeIncidencia);
                    }
                    error.Close();
                }

                /* Generar SOAP Request de timbrado */
                string SOAPDirectory = @"C:\SiscomSoft\SOAP";
                if (!Directory.Exists(SOAPDirectory))
                {
                    Directory.CreateDirectory(SOAPDirectory);
                }
                StreamWriter  XML  = new StreamWriter(SOAPDirectory + @"\" + "SOAP_ENVELOPE_" + nameFile); //Direccion donde guardaremos el SOAP Envelope
                XmlSerializer soap = new XmlSerializer(oStamp.GetType());                                  //Obtenemos los datos del SOAP de la variable Solicitud
                soap.Serialize(XML, oStamp);
                XML.Close();
                /* Generar SOAP Request de timbrado */
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
 private void timbrar()
 {
     Models.Configuration configuracion = new Models.Configuration();
     using (configuracion)
     {
         List <Models.Configuration> config = configuracion.getConfiguration();
         //Instancias del timbrado
         Timbrado.StampSOAP selloSOAP = new Timbrado.StampSOAP();
         stamp         oStamp         = new stamp();
         stampResponse selloResponse  = new stampResponse();
         //Cargas tu archivo xml
         XmlDocument xmlDocument = new XmlDocument();
         xmlDocument.Load(config[0].Ruta_factura + txtFolio.Text + ".xml");
         //xmlDocument.Load(config[0].Ruta_factura + txtFolio.Text + ".xml");
         //Conviertes el archivo en byte
         byte[] byteXmlDocument = Encoding.UTF8.GetBytes(xmlDocument.OuterXml);
         //Conviertes el byte resultado en base64
         string stringByteXmlDocument = Convert.ToBase64String(byteXmlDocument);
         //Convirtes el resultado nuevamente a byte
         byteXmlDocument = Convert.FromBase64String(stringByteXmlDocument);
         //Timbras el archivo
         oStamp.xml      = byteXmlDocument;
         oStamp.username = "******";
         oStamp.password = "******";
         //Generamos request
         String usuario;
         usuario = Environment.UserName;
         String        url  = config[0].Ruta_factura;
         StreamWriter  XML  = new StreamWriter(url + "SOAP_Request.xml");             //Direccion donde guardaremos el SOAP Envelope
         XmlSerializer soap = new XmlSerializer(oStamp.GetType());                    //Obtenemos los datos del objeto oStamp que contiene los parámetros de envió y es de tipo stamp()
         soap.Serialize(XML, oStamp);
         XML.Close();
         //Recibes la respuesta de timbrado
         selloResponse = selloSOAP.stamp(oStamp);
         try
         {
             MessageBox.Show("No se timbro el XML" + "\nCódigo de error: " + selloResponse.stampResult.Incidencias[0].CodigoError.ToString() + "\nMensaje: " + selloResponse.stampResult.Incidencias[0].MensajeIncidencia);
         }
         catch (Exception)
         {
             MessageBox.Show(selloResponse.stampResult.CodEstatus.ToString());
             Models.Facturas factura = new Models.Facturas();
             using (factura)
             {
                 factura.Uuid  = selloResponse.stampResult.UUID.ToString();
                 factura.Folio = Convert.ToInt32(txtFolio.Text);
                 factura.Xml   = selloResponse.stampResult.xml.ToString();
                 factura.update_uuid();
             }
             StreamWriter XMLL = new StreamWriter(url + txtFolio.Text + ".xml");
             XMLL.Write(selloResponse.stampResult.xml);
             XMLL.Close();
             File.Delete(url + "SOAP_Request.xml");
         }
     }
 }