Beispiel #1
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_C.Entidades.Certificado Certificado, eFact_C.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_C.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");
     }
 }