public string Emissao(NfseTransmitirLote lote) { DocumentoXml documento = _repository.Get(4); string testeSerilize = XmlUtils.Serializar(lote, true); byte[] byteArray = Encoding.ASCII.GetBytes(testeSerilize); MemoryStream stream = new MemoryStream(byteArray); var oldDocument = XDocument.Load(stream); string xml = processarXml(documento.Xml, oldDocument).ToString(); XmlDocument docAlimentado = new XmlDocument(); docAlimentado.LoadXml(xml.ToString()); var certificate = new X509Certificate2(Path.Combine(Directory.GetCurrentDirectory(), "certificado.pfx"), "QUESTOR1234"); XmlNodeList nodeAssinatura = docAlimentado.GetElementsByTagName("Assinatura"); for (int i = (nodeAssinatura.Count - 1); i >= 0; i--) { XmlNode item = nodeAssinatura.Item(i); XmlDocument xmlSignature = XmlUtils.GetXmlDocument(XmlUtils.GetSignature(XmlUtils.GetXmlDocument(item.InnerXml), item.FirstChild.Attributes["id"].Value, certificate)); XmlNode Signature = item.OwnerDocument.ImportNode(xmlSignature.DocumentElement, true); XmlNode XmlAssinado = item.OwnerDocument.ImportNode(XmlUtils.GetXmlDocument(item.InnerXml).DocumentElement, true); item.ParentNode.AppendChild(XmlAssinado); item.ParentNode.AppendChild(Signature); var xml_node = docAlimentado.GetElementsByTagName("Assinatura")[i]; xml_node.ParentNode.RemoveChild(xml_node); } xml = docAlimentado.InnerXml; SoapWebService soap = new SoapWebService("http://nfse1.publica.inf.br/chapeco_nfse_integracao/Services?wsdl", certificate); var resultSoap = soap.ExecuteMethod <string>("RecepcionarLoteRps", new object[] { xml }); return(JsonConvert.SerializeXmlNode(XmlUtils.GetXmlDocument(resultSoap.Replace(@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>", "")))); }
private NfseTransmitir getNotaNumero(NfseTransmitirLote lote) { return(lote.Notas.Where(x => x.NumeroRps == lote.NumeroLote).First <NfseTransmitir>()); }
private string verificaIdAssinatura(NfseTransmitirLote lote) { NfseTransmitir nota = getNotaNumero(lote); return((nota.IdAssinatura != null) ? nota.IdAssinatura : "rps" + lote.NumeroLote); }