Ejemplo n.º 1
0
        private string ValidarNumeroLote(string numeroLote)
        {
            if (numeroLote.IsNullOrEmpty())
            {
                numeroLote = DFeHelper.GerarNumeroLote();
            }

            return(numeroLote);
        }
Ejemplo n.º 2
0
        public NFeRecepcaoEventoResposta RecepcaoEvento(NFeEvento evento)
        {
            lock (serviceLock)
            {
                switch (evento.InfEvento.TpEvento)
                {
                case NFeTipoEvento.Cancelamento:
                    Schema = NFeSchema.EnvEventoCancNFe;
                    break;

                case NFeTipoEvento.CartaCorrecao:
                    Schema = NFeSchema.EnvCCe;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("O evento informado é desconhecido ou não está implementado");
                }

                var request = new StringBuilder();
                request.Append($"<envEvento xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"{evento.Versao.GetDFeValue()}\">");
                request.Append($"<idLote>{DFeHelper.GerarNumeroLote()}</idLote>");

                var saveOptions = Configuracoes.ObterOptions();
                evento.Assinar(Certificado, saveOptions);
                var xmlEvento = evento.GetXml(saveOptions);
                GravarXmlAssinado(xmlEvento, evento.ObterNomeXml());

                request.Append(xmlEvento);
                request.Append("</envEvento>");

                var dadosMsg = request.ToString();
                ValidateMessage(dadosMsg);

                var doc = new XmlDocument();
                doc.LoadXml(dadosMsg);

                var value       = new RecepcaoEventoRequest(doc);
                var returnValue = Channel.RecepcaoEvento(value);
                return(new NFeRecepcaoEventoResposta(dadosMsg, returnValue.Mensagem.OuterXml, EnvelopeSoap, RetornoWS));
            }
        }