public void EnviarIBK(out eFact_RN.IBK.lote_response Lr, FeaEntidades.InterFacturas.lote_comprobantes lc, string certificado) { IBK.lote_comprobantes lcIBK = new IBK.lote_comprobantes(); lcIBK = Fea2Ibk(lc); IBK.FacturaWebServiceConSchema objIBK; objIBK = new IBK.FacturaWebServiceConSchema(); objIBK.Url = System.Configuration.ConfigurationManager.AppSettings["URLinterfacturas"]; objIBK.Timeout = 3900000; if (System.Configuration.ConfigurationManager.AppSettings["Proxy"] != null && System.Configuration.ConfigurationManager.AppSettings["Proxy"] != "") { System.Net.WebProxy wp = new System.Net.WebProxy(System.Configuration.ConfigurationManager.AppSettings["Proxy"], false); string usuarioProxy = System.Configuration.ConfigurationManager.AppSettings["UsuarioProxy"]; string claveProxy = System.Configuration.ConfigurationManager.AppSettings["ClaveProxy"]; string dominioProxy = System.Configuration.ConfigurationManager.AppSettings["DominioProxy"]; System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(usuarioProxy, claveProxy, dominioProxy); wp.Credentials = networkCredential; objIBK.Proxy = wp; } string storeLocation = System.Configuration.ConfigurationManager.AppSettings["StoreLocation"]; X509Store store; if (storeLocation == "CurrentUser") { store = new X509Store(StoreLocation.CurrentUser); } else { store = new X509Store(StoreLocation.LocalMachine); } store.Open(OpenFlags.ReadOnly); X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, certificado, true); if (col.Count.Equals(1)) { //objIBK.RequestEncoding = System.Text.Encoding.GetEncoding("iso-8859-1"); objIBK.ClientCertificates.Add(col[0]); System.Threading.Thread.Sleep(1000); IBK.lote_comprobantes_response lcr = objIBK.receiveFacturasConSchema(lcIBK); IBK.lote_response lr = new eFact_RN.IBK.lote_response(); try { lr = ((IBK.lote_response)lcr.Item); if (lr.estado == "OK") { Lr = lr; } else { Lr = lr; StringBuilder errorText = new StringBuilder(); if (Lr.errores_lote != null) { errorText.Append("Nro. de Lote: [" + Lr.id_lote + "] \r\n"); foreach (eFact_RN.IBK.error elote in Lr.errores_lote) { errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n"); } } if (Lr.comprobante_response != null) { foreach (eFact_RN.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 (eFact_RN.IBK.error ecomprobante in comprobante.errores_comprobante) { errorText.Append(ecomprobante.codigo_error + " - " + ecomprobante.descripcion_error + " \r\n"); } } } } throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.Lote.ProblemasEnvio(errorText.ToString()); } } 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 eFact_RN.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"); } } } throw new Exception(errorText.ToString()); } } else { throw new Exception("Su certificado no está disponible en nuestro repositorio"); } }
public string EnviarIBK(FeaEntidades.InterFacturas.lote_comprobantes lc, string certificado) { IBK.lote_comprobantes lcIBK = new IBK.lote_comprobantes(); lcIBK = Fea2Ibk(lc); IBK.FacturaWebServiceConSchema objIBK; objIBK = new IBK.FacturaWebServiceConSchema(); objIBK.Url = System.Configuration.ConfigurationManager.AppSettings["URLinterfacturas"]; if (System.Configuration.ConfigurationManager.AppSettings["Proxy"] != null && System.Configuration.ConfigurationManager.AppSettings["Proxy"] != "") { System.Net.WebProxy wp = new System.Net.WebProxy(System.Configuration.ConfigurationManager.AppSettings["Proxy"], false); string usuarioProxy = System.Configuration.ConfigurationManager.AppSettings["UsuarioProxy"]; string claveProxy = System.Configuration.ConfigurationManager.AppSettings["ClaveProxy"]; string dominioProxy = System.Configuration.ConfigurationManager.AppSettings["DominioProxy"]; System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(usuarioProxy, claveProxy, dominioProxy); wp.Credentials = networkCredential; objIBK.Proxy = wp; } X509Store store = new X509Store(StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly); X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, certificado, true); if (col.Count.Equals(1)) { objIBK.ClientCertificates.Add(col[0]); System.Threading.Thread.Sleep(1000); IBK.lote_comprobantes_response lcr = objIBK.receiveFacturasConSchema(lcIBK); string resultado = string.Empty; if (!((IBK.lote_response)(lcr.Item)).estado.Equals("OK")) { if (((IBK.lote_response)lcr.Item).errores_lote != null) { resultado = ((IBK.lote_response)lcr.Item).errores_lote[0].descripcion_error; } else { resultado = ((IBK.lote_response)lcr.Item).comprobante_response[0].errores_comprobante[0].descripcion_error; } throw new Exception(resultado); } else { resultado = "Comprobante enviado satisfactoriamente a Interfacturas"; } return resultado; } else { throw new Exception("Su certificado no está disponible en nuestro repositorio"); } }