예제 #1
0
        /// <summary>
        ///     Adiciona e valida uma nota a ser enviada.
        /// </summary>
        /// <param name="nota"></param>
        public void AdicionarNota(Nota nota)
        {
            var bllAssinatura = new AssinaturaDeXml();
            var bllXml = new Xml();

            //Verifica se já passou o limite de notas por lote (regra do SEFAZ). 
            if (notaLista.Count >= 50)
            {
                throw new Exception("Limite máximo por lote é de 50 arquivos");
            }

            //Assina a nota
            try
            {
                bllAssinatura.AssinarNota(nota, NFeContexto.Certificado, "NFe");
            }
            catch (Exception e)
            {
                throw new Exception("Erro ao assinar Nota: " + e.Message);
            }

            //Verifica se a nota está de acordo com o schema, se não estiver vai disparar um erro
            try
            {
                bllXml.ValidaSchema(nota.CaminhoFisico,
                    Util.ContentFolderSchemaValidacao + "\\" + NFeContexto.Versao.PastaXml + "\\" + arquivoSchema);
            }
            catch (Exception e)
            {
                throw new Exception("Erro ao validar Nota: " + e.Message);
            }

            //Adiciona para a lista do lote a serem enviadas
            notaLista.Add(nota);
        }
예제 #2
0
        private RetornoSimples EnviarEvento(StringBuilder eventoXml, String id, String arquivoEvento, String schema)
        {
            var documentXml = Assinar(eventoXml, id, schema);

            var xmlDoc = new XmlDocument();
            xmlDoc.Load(arquivoEvento);

            var conteudoXml = xmlDoc.OuterXml;


            var nota = new Nota(NFeContexto) {CaminhoFisico = arquivoEvento};

            var bllXml = new Xml();

            var xmlString = new StringBuilder();
            xmlString.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            xmlString.Append("<envEvento versao=\"1.00\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">");
            xmlString.Append("	<idLote>0131318</idLote>");
            xmlString.Append(conteudoXml);
            xmlString.Append("</envEvento>");

            var SW_2 = File.CreateText(arquivoEvento);
            SW_2.Write(xmlString.ToString());
            SW_2.Close();

            //Verifica se a nota está de acordo com o schema, se não estiver vai disparar um erro
            try
            {
                bllXml.ValidaSchema(arquivoEvento,
                    Util.ContentFolderSchemaValidacao + "\\" + NFeContexto.Versao.PastaXml + "\\" + schema);
            }
            catch (Exception e)
            {
                throw new Exception("Erro ao validar Nota: " + e.Message);
            }

            var recepcao = new RecepcaoEvento2.RecepcaoEvento();
            var cabecalho = new nfeCabecMsg();
            cabecalho.cUF = "35";
            cabecalho.versaoDados = "1.00";

            recepcao.nfeCabecMsgValue = cabecalho;
            recepcao.ClientCertificates.Add(NFeContexto.Certificado);

            var resposta = recepcao.nfeRecepcaoEvento(Xml.StringToXml(xmlString.ToString()));

            var status = resposta["retEvento"]["infEvento"]["xMotivo"].InnerText;
            var motivo = resposta["retEvento"]["infEvento"]["cStat"].InnerText;
            return new RetornoSimples(status, motivo);
        }