public string ProcesarRespuestaAceptacionRechazo(string RfcReceptor, string fecha, string rfcPac, List <SolicitudAceptacionRechazoFolios> F, SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignatureType asig) { string result; try { AceptacionRechazoServiceClient CFDI = new AceptacionRechazoServiceClient(); AcuseAceptacionRechazo A = new AcuseAceptacionRechazo(); HttpRequestMessageProperty tokenAutenticacion = this.AutenticaServicio(); using (new OperationContextScope(CFDI.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = tokenAutenticacion; A = CFDI.ProcesarRespuesta(new SolicitudAceptacionRechazo { Fecha = Convert.ToDateTime(fecha), RfcPacEnviaSolicitud = rfcPac, RfcReceptor = RfcReceptor, Signature = asig, Folios = F.ToArray() }); result = AccesoServicios.GetXMLFromObject(A); } } catch (Exception exception) { AccesoServicios.Log.Error("(Envio) Error al enviar los CFDI's " + exception.ToString()); result = null; } return(result); }
public string ConsultaCFDIRelacionadosRequest(string RfcPacEnviaSolicitud, string RfcReceptor, string RfcEmisor, string Uuid, SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asig) { string result; try { PeticionConsultaRelacionados D = new PeticionConsultaRelacionados(); CfdiConsultaRelacionadosServiceClient CFDI = new CfdiConsultaRelacionadosServiceClient(); D.RfcPacEnviaSolicitud = RfcPacEnviaSolicitud; if (!string.IsNullOrEmpty(RfcReceptor)) { D.RfcReceptor = RfcReceptor; } D.Signature = asig; D.Uuid = Uuid; if (!string.IsNullOrEmpty(RfcEmisor)) { D.RfcEmisor = RfcEmisor; } HttpRequestMessageProperty tokenAutenticacion = this.AutenticaServicio(); using (new OperationContextScope(CFDI.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = tokenAutenticacion; ConsultaRelacionados x = CFDI.ProcesarRespuesta(D); string xml = AccesoServicios.GetXMLFromObject(x); result = xml; } } catch (Exception exception) { AccesoServicios.Log.Error("(ConsultaRelacionados) Error al consultar los CFDI's " + exception.ToString()); result = null; } return(result); }
public SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType Asignature(string strPPrivada, Encabezado encLMetadata, string pass, string strCertificado) { SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType result; try { string strPXmlFirmado = ""; SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType Asig = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType(); Asig.Id = "Signature"; Asig.SignedInfo = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignedInfoType(); Asig.SignedInfo.Id = "Signature-SignedInfo"; Asig.SignedInfo.CanonicalizationMethod = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.CanonicalizationMethodType(); Asig.SignedInfo.CanonicalizationMethod.Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n20010315"; Asig.SignedInfo.SignatureMethod = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureMethodType(); Asig.SignedInfo.SignatureMethod.Algorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"; Asig.SignedInfo.Reference = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.ReferenceType(); Asig.SignedInfo.Reference.URI = "#Certificate1"; List <SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.TransformType> T = new List <SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.TransformType>(); T.Add(new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.TransformType { Algorithm = "http://www.w3.org/2000/09/xmldsig#envelopedsignature" }); Asig.SignedInfo.Reference.Transforms = T.ToArray(); Asig.SignedInfo.Reference.DigestMethod = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.DigestMethodType(); Asig.SignedInfo.Reference.DigestMethod.Algorithm = "http://www.w3.org/2000/09/xmldsig#sha1"; if (File.Exists(strPPrivada + ".pem")) { strPPrivada += ".pem"; } string ext = Path.GetExtension(strPPrivada); AccesoServicios.SignXmlFile(this.ArmarXmlPreFirma(encLMetadata), ref strPXmlFirmado, OpensslKey.DecodePrivateKey(File.ReadAllBytes(strPPrivada), pass, ext)); string hex = strPXmlFirmado.Substring(strPXmlFirmado.IndexOf("<DigestValue>") + 13, strPXmlFirmado.IndexOf("</DigestValue>") - strPXmlFirmado.IndexOf("<DigestValue>") - 13); Asig.SignedInfo.Reference.DigestValue = Convert.FromBase64String(hex); Asig.SignatureValue = Convert.FromBase64String(strPXmlFirmado.Substring(strPXmlFirmado.IndexOf("<SignatureValue>") + 16, strPXmlFirmado.IndexOf("</SignatureValue>") - strPXmlFirmado.IndexOf("<SignatureValue>") - 16)); X509Certificate2 x509 = new X509Certificate2(strCertificado); Asig.KeyInfo = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.KeyInfoType(); Asig.KeyInfo.X509Data = new SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.X509DataType(); Asig.KeyInfo.X509Data.X509Certificate = File.ReadAllBytes(strCertificado); Asig.KeyInfo.Id = "Certificate1"; result = Asig; } catch (Exception exception) { AccesoServicios.Log.Error("(Asignature) Error al generar la firma de los CFDI's " + exception.ToString()); result = null; } return(result); }
public string ConsultaAceptacionRechazo(string RfcReceptor) { string result; try { AceptacionRechazoServiceClient CFDI = new AceptacionRechazoServiceClient(); HttpRequestMessageProperty tokenAutenticacion = this.AutenticaServicio(); using (new OperationContextScope(CFDI.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = tokenAutenticacion; AcusePeticionesPendientes x = CFDI.ObtenerPeticionesPendientes(RfcReceptor); string xml = AccesoServicios.GetXMLFromObject(x); result = xml; } } catch (Exception exception) { AccesoServicios.Log.Error("(Consultar) Error al consultar los CFDI's " + exception.ToString()); result = null; } return(result); }
public string CancelarBloqueCfdi(string directorioLog, string directorioAcuse, Encabezado encLMetadata, string strPPrivada, string pass, string strCertificado, ref SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.Acuse cAcuse) { string result; try { AccesoServicios.Logger.Info("Privada: " + strPPrivada); AccesoServicios.Logger.Info("Certificado: " + strCertificado); AccesoServicios.Logger.Info("rfc:" + encLMetadata.RfcEmisor); AccesoServicios.Logger.Info("fecha:" + encLMetadata.Fecha); AccesoServicios.Logger.Info("uuid:" + encLMetadata.LisMListaFolios[0].ToString()); string strPXmlFirmado = ""; if (File.Exists(strPPrivada + ".pem")) { strPPrivada += ".pem"; } string ext = Path.GetExtension(strPPrivada); AccesoServicios.SignXmlFile(this.ArmarXmlPreFirma(encLMetadata), ref strPXmlFirmado, OpensslKey.DecodePrivateKey(File.ReadAllBytes(strPPrivada), pass, ext)); AccesoServicios.Logger.Info(strPXmlFirmado); SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.SignatureType a = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.SignatureType(); SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.ReferenceType reference = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.ReferenceType { URI = "" }; XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform(); a.SignedInfo = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.SignedInfoType { Reference = reference }; string hex = strPXmlFirmado.Substring(strPXmlFirmado.IndexOf("<DigestValue>") + 13, strPXmlFirmado.IndexOf("</DigestValue>") - strPXmlFirmado.IndexOf("<DigestValue>") - 13); a.SignedInfo.Reference.DigestValue = Convert.FromBase64String(hex); a.SignedInfo.Reference.DigestMethod = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.DigestMethodType { Algorithm = "http://www.w3.org/2000/09/xmldsig#sha1" }; a.SignedInfo.Reference.Transforms = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.TransformType[] { new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.TransformType() }; a.SignedInfo.Reference.Transforms[0].Algorithm = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"; a.SignedInfo.CanonicalizationMethod = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.CanonicalizationMethodType { Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" }; a.SignedInfo.SignatureMethod = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.SignatureMethodType { Algorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1" }; a.SignatureValue = Convert.FromBase64String(strPXmlFirmado.Substring(strPXmlFirmado.IndexOf("<SignatureValue>") + 16, strPXmlFirmado.IndexOf("</SignatureValue>") - strPXmlFirmado.IndexOf("<SignatureValue>") - 16)); X509Certificate2 x509 = new X509Certificate2(strCertificado); a.KeyInfo = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.KeyInfoType(); a.KeyInfo.X509Data = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.X509DataType(); a.KeyInfo.X509Data.X509IssuerSerial = new SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.X509IssuerSerialType(); a.KeyInfo.X509Data.X509IssuerSerial.X509IssuerName = x509.IssuerName.Name.ToString(); a.KeyInfo.X509Data.X509IssuerSerial.X509SerialNumber = x509.SerialNumber; a.KeyInfo.X509Data.X509Certificate = File.ReadAllBytes(strCertificado); Console.WriteLine("Enviando Cancelación..."); string a2 = a.ToString(); Cancelacion mensajeCancelacion = new Cancelacion { RfcEmisor = encLMetadata.RfcEmisor, Fecha = Convert.ToDateTime(encLMetadata.Fecha), Signature = a }; mensajeCancelacion.Folios = new CancelacionFolios[encLMetadata.LisMListaFolios.Count]; for (int i = 0; i < encLMetadata.LisMListaFolios.Count; i++) { mensajeCancelacion.Folios[i] = new CancelacionFolios { UUID = encLMetadata.LisMListaFolios[i].ToString() }; } if (mensajeCancelacion.Folios.Count <CancelacionFolios>() > 0) { Console.WriteLine("Autenticando..."); HttpRequestMessageProperty tokenAutenticacion = this.AutenticaServicio(); using (new OperationContextScope(this.ClienteCancelacion.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = tokenAutenticacion; Console.WriteLine("Cancelando..."); SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.Acuse acuseCancelacion = this.ClienteCancelacion.CancelaCFD(mensajeCancelacion); MemoryStream acuseStream = new MemoryStream(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.Acuse)); xmlSerializer.Serialize(acuseStream, acuseCancelacion); acuseStream.Seek(0L, SeekOrigin.Begin); StreamReader acuseReader = new StreamReader(acuseStream); AccesoServicios.Log.Info("Terminando el proceso..."); cAcuse = acuseCancelacion; result = acuseReader.ReadToEnd(); return(result); } } result = string.Empty; return(result); } catch (Exception exception) { AccesoServicios.Log.Error("(CancelarBloqueCfdi) Error al cancelar los CFDI's " + exception.ToString()); } result = ""; return(result); }