Example #1
0
        public FeaEntidades.InterFacturas.lote_comprobantes ConsultarIBK(out List<FeaEntidades.InterFacturas.error> RespErroresLote, out List<FeaEntidades.InterFacturas.error> RespErroresComprobantes, eFact_Tester.IBK.consulta_lote_comprobantes clc, string url, eFact_Tester.Entidades.Certificado Certificado, eFact_Tester.Entidades.Proxy Proxy)
        {
            FeaEntidades.InterFacturas.lote_comprobantes lc = new FeaEntidades.InterFacturas.lote_comprobantes();
            lc.cabecera_lote = new FeaEntidades.InterFacturas.cabecera_lote();
            lc.comprobante = new FeaEntidades.InterFacturas.comprobante[1];
            IBK.error[] respErroresLote = new IBK.error[0];
            IBK.error[] respErroresComprobantes = new IBK.error[0];
			IBK.FacturaWebServiceConSchema objIBK;
			objIBK = new IBK.FacturaWebServiceConSchema();
            objIBK.Url = url;
            if (Proxy != null)
            {
                System.Net.WebProxy wp = new System.Net.WebProxy(Proxy.Servidor, false);
                System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(Proxy.Usuario, Proxy.Clave, Proxy.Dominio);
                wp.Credentials = networkCredential;
                objIBK.Proxy = wp;
            }
            X509Store store;
            if (Certificado.LugarDeAlmacenamiento == eFact_Tester.Entidades.Certificado.Almacenamiento.CurrentUser)
            {
                store = new X509Store(StoreLocation.CurrentUser);
            }
            else
            {
                store = new X509Store(StoreLocation.LocalMachine);
            }
            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, Certificado.Numero, true);
            if (col.Count.Equals(1))
            {
                objIBK.ClientCertificates.Add(col[0]);
                System.Threading.Thread.Sleep(1000);
                IBK.consulta_lote_comprobantes_response clcr = objIBK.getLoteFacturasConSchema(clc);
                IBK.consulta_lote_response clr;
                try
                {
                    clr = (IBK.consulta_lote_response)clcr.Item;
                    IBK.lote_comprobantes lcIBK = (IBK.lote_comprobantes)clr.Item;
                    lc = Ibk2Fea(lcIBK);
                }
                catch (InvalidCastException)
                {
                    StringBuilder errorText = new StringBuilder();
                    if (clcr.Item != null)
                    {
                        errorText.Append("Nro. de Lote: [" + clc.id_lote + "] \r\n");
                        if (clcr.Item.GetType() == typeof(IBK.consulta_lote_response))
                        {
                            clr = (IBK.consulta_lote_response)clcr.Item;
                            IBK.consulta_lote_responseErrores_consulta errores = (IBK.consulta_lote_responseErrores_consulta)clr.Item;
                            foreach (IBK.error elote in errores.error)
                            {
                                errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n");
                            }
                            RespErroresLote = Ibk2Fea(errores.error);
                        }
                        else
                        {
                            IBK.consulta_lote_comprobantes_responseErrores_response clcrEr;
                            clcrEr = (IBK.consulta_lote_comprobantes_responseErrores_response)clcr.Item;
                            foreach (IBK.error elote in clcrEr.error)
                            {
                                errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n");
                            }
                            RespErroresComprobantes = Ibk2Fea(clcrEr.error);
                        }
                    }
                    throw new Exception(errorText.ToString());
                }
                RespErroresLote = new List<FeaEntidades.InterFacturas.error>();
                RespErroresComprobantes = new List<FeaEntidades.InterFacturas.error>();
                return lc;
            }
            else
            {
                throw new Exception("Su certificado no está disponible en nuestro repositorio");
            }
        }
Example #2
0
 public FeaEntidades.InterFacturas.lote_response EnviarIBK(out List<FeaEntidades.InterFacturas.error> RespErroresLote, out List<FeaEntidades.InterFacturas.error> RespErroresComprobantes, FeaEntidades.InterFacturas.lote_comprobantes lc, string url, eFact_Tester.Entidades.Certificado Certificado, eFact_Tester.Entidades.Proxy Proxy)
 {
     FeaEntidades.InterFacturas.lote_response Lr = new FeaEntidades.InterFacturas.lote_response();
     IBK.lote_comprobantes lcIBK = new IBK.lote_comprobantes();
     lcIBK = Fea2Ibk(lc);
     IBK.error[] respErroresLote = new IBK.error[0];
     IBK.error[] respErroresComprobantes = new IBK.error[0];
     IBK.FacturaWebServiceConSchema objIBK;
     objIBK = new IBK.FacturaWebServiceConSchema();
     objIBK.Url = url;
     if (Proxy != null)
     {
         System.Net.WebProxy wp = new System.Net.WebProxy(Proxy.Servidor, false);
         System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(Proxy.Usuario, Proxy.Clave, Proxy.Dominio);
         wp.Credentials = networkCredential;
         objIBK.Proxy = wp;
     }
     X509Store store;
     if (Certificado.LugarDeAlmacenamiento == eFact_Tester.Entidades.Certificado.Almacenamiento.CurrentUser)
     {
         store = new X509Store(StoreLocation.CurrentUser);
     }
     else
     {
         store = new X509Store(StoreLocation.LocalMachine);
     }
     store.Open(OpenFlags.ReadOnly);
     X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, Certificado.Numero, true);
     if (col.Count.Equals(1))
     {
         objIBK.ClientCertificates.Add(col[0]);
         IBK.lote_comprobantes_response lcr = objIBK.receiveFacturasConSchema(lcIBK);
         IBK.lote_response lr = new IBK.lote_response();
         RespErroresLote = new List<FeaEntidades.InterFacturas.error>();
         RespErroresComprobantes = new List<FeaEntidades.InterFacturas.error>();
         try
         {
             lr = ((IBK.lote_response)lcr.Item);
             if (lr.estado == "OK")
             {
                 Lr = Ibk2Fea(lr);
             }
             else
             {
                 Lr = Ibk2Fea(lr);
                 StringBuilder errorText = new StringBuilder();
                 if (lr.errores_lote != null)
                 {
                     errorText.Append("Nro. de Lote: [" + Lr.id_lote + "] \r\n");
                     foreach (IBK.error elote in lr.errores_lote)
                     {
                         errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n");
                     }
                     RespErroresLote.AddRange(Ibk2Fea(lr.errores_lote));
                 }
                 if (lr.comprobante_response != null)
                 {
                     foreach (IBK.comprobante_response comprobante in lr.comprobante_response)
                     {
                         if (comprobante.errores_comprobante != null)
                         {
                             if (lr.errores_lote != null)
                             {
                                 errorText.Append("\r\n");
                             }
                             errorText.Append("Punto de Venta: [" + comprobante.punto_de_venta + "]  Tipo de Comprobante: [" + comprobante.tipo_de_comprobante + "]  Nro. de Comprobante: [" + comprobante.numero_comprobante + "] \r\n");
                             foreach (IBK.error ecomprobante in comprobante.errores_comprobante)
                             {
                                 errorText.Append(ecomprobante.codigo_error + " - " + ecomprobante.descripcion_error + " \r\n");
                             }
                             RespErroresComprobantes.AddRange(Ibk2Fea(comprobante.errores_comprobante));
                         }
                     }
                 }
                 throw new Exception(errorText.ToString());
             }
             return Lr;
         }
         catch (InvalidCastException)
         {
             StringBuilder errorText = new StringBuilder();
             if (lcr.Item != null)
             {
                 if (lcr.Item.GetType() == typeof(IBK.lote_comprobantes_responseErrores_response))
                 {
                     IBK.lote_comprobantes_responseErrores_response lcrEr = new IBK.lote_comprobantes_responseErrores_response();
                     errorText.Append("Nro. de Lote: [" + lc.cabecera_lote.id_lote + "] \r\n");
                     lcrEr = (IBK.lote_comprobantes_responseErrores_response)lcr.Item;
                     foreach (IBK.error error in lcrEr.error)
                     {
                         errorText.Append(error.codigo_error + " - " + error.descripcion_error + " \r\n");
                     }
                     RespErroresLote = Ibk2Fea(lcrEr.error);
                 }
             }
             throw new Exception(errorText.ToString());
         }
     }
     else
     {
         throw new Exception("Su certificado no está disponible en nuestro repositorio");
     }
 }