public TRetConsReciNFe ConsultaRecLote2(TConsReciNFe consReciNFe, TRetEnviNFe retEnvNFe, X509Certificate2 cert) { XmlNode strRetorno = null; C_WebService.ListaUrl listaURL = default(C_WebService.ListaUrl); listaURL = WsUrls.BuscaURL(retEnvNFe.cUF, retEnvNFe.tpAmb); string nomeArquivoPedido = _PastaLog + retEnvNFe.infRec.nRec + "-ped-rec.xml"; string nomeArquivoRetProc = _PastaLog + retEnvNFe.infRec.nRec + "-pro-rec.xml"; try { RetRecepcao2.NfeRetRecepcao2 wsMsg = default(RetRecepcao2.NfeRetRecepcao2); RetRecepcao2.nfeCabecMsg cab = new RetRecepcao2.nfeCabecMsg(); //UF E VERSÃO DO CABEÇALHO cab.cUF = PegarCodigoUF(retEnvNFe.cUF); cab.versaoDados = retEnvNFe.versao; //CRIA UMA INSTANCIA DA CONEXÃO COM O WEBSERVICE wsMsg = new RetRecepcao2.NfeRetRecepcao2(listaURL.UrlNfeRetRecepcao); //ASSOCIA CABEÇALHO NFE wsMsg.nfeCabecMsgValue = cab; //DEFINE TEMPO MAXIMO DE ESPERA POR RETORNO wsMsg.Timeout = 100000; //ASSOCIA CERTIFICADO A CONEXAO WEBSERVICE wsMsg.ClientCertificates.Add(cert); //DEFINE PROTOCOLO USADO NA CONEXÃO //wsMsg.SoapVersion = SoapProtocolVersion.Soap12 //CRIA UM NOVO DOCUMENTO XML XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(Funcoes.RemoveNameSpaceFromXml(consReciNFe.Serialize())); xmldoc.Save(nomeArquivoPedido); //ENVIA CONSULTA PARA SEFAZ E OBTEM RETORNO EM FORMATO STRING strRetorno = wsMsg.nfeRetRecepcao2(xmldoc); TRetConsReciNFe retornoReciNFe = new TRetConsReciNFe(); XmlDocument retornoXML = new XmlDocument(); retornoXML.LoadXml(strRetorno.OuterXml); retornoXML.Save(nomeArquivoRetProc); retornoReciNFe = TRetConsReciNFe.LoadFromFile(nomeArquivoRetProc); retornoReciNFe.XmlRetorno = retornoXML; return(retornoReciNFe); } catch (Exception) { throw new ACBr.Net.NFe.Exceptions.ConsultaRecLote2Exception("Falha ao consultar o recebimento de lote de NFe.", consReciNFe, retEnvNFe, cert); } }
public TRetConsReciNFe ConsultarLote(TConsReciNFe consRecibo, TRetEnviNFe retEnvio) { throw new NotImplementedException("Trocar para consulta de RetAutorizacao"); /*var ws = new C_WebService(Configuracao.PastaLog); * var reciboNFe = ws.ConsultaRecLote2(consRecibo, retEnvio, Certificado); * if (reciboNFe.protNFe == null) return reciboNFe; * foreach (var item in reciboNFe.protNFe) * { * var nota = NotasFiscais.FirstOrDefault(n => n.NFe.infNFe.Id == "NFe" + item.infProt.chNFe); * if (nota == null) continue; * nota.protNFe = item; * * if (item.infProt.cStat == "100") * { * SalvarNFe(ref nota); * } * } * return reciboNFe;*/ }
public void Enviar(Entidade_Recibo ObjEnt, out Entidade_Recibo objDados) { ReciNFe = new TConsReciNFe(); docTran = new XmlDocument(); ns = new XmlSerializerNamespaces(); Settings = new XmlWriterSettings(); xmlStatus = new XmlSerializer(typeof(TConsReciNFe)); ReciNFe = new TConsReciNFe(ObjEnt.Recibo, ObjEnt.TpAmb); Settings.Encoding = UTF8Encoding.UTF8; Settings.NewLineHandling = NewLineHandling.None; Settings.Indent = true; Settings.IndentChars = ""; ns.Add(string.Empty, "http://www.portalfiscal.inf.br/nfe"); Sw = new UTF8StringWriter(); Wx = XmlWriter.Create(Sw, Settings); xmlStatus.Serialize(Sw, ReciNFe, ns); string xmlGer = Sw.ToString(); docTran.LoadXml(xmlGer); docTran.PreserveWhitespace = false; CertEmpresa = AssinaturaDigital.FindCertOnStore(ObjEnt.Loja); try { EnviarXml(docTran, CertEmpresa, ref ObjEnt); objDados = ObjEnt; } catch (Exception Ex) { Mensagem.MensagemErro(Mensagem.TipoMensagem.RetAutoriz, "Saida", Ex.Message.ToString()); objDados = null; } }
public ConsultaRecLote2Exception(string message, TConsReciNFe consReciNFe, TRetEnviNFe retEnvNFe, X509Certificate2 cert) : base(message) { this.consReciNFe = consReciNFe; this.retEnvNFe = retEnvNFe; this.cert = cert; }
private List<RetornoNotaFiscal> ConsultarReciboLoteContingencia(string nRec, Modelo modelo) { var config = _configuracaoService.GetConfiguracao(); X509Certificate2 certificado; var certificadoEntity = _certificadoRepository.GetCertificado(); if (!string.IsNullOrWhiteSpace(certificadoEntity.Caminho)) certificado = _certificateManager.GetCertificateByPath(certificadoEntity.Caminho, RijndaelManagedEncryption.DecryptRijndael(certificadoEntity.Senha)); else certificado = _certificateManager.GetCertificateBySerialNumber(certificadoEntity.NumeroSerial, false); var consultaRecibo = new TConsReciNFe { versao = "4.00", tpAmb = config.IsProducao ? XmlSchemas.NfeRetAutorizacao.Envio.TAmb.Item1 : XmlSchemas.NfeRetAutorizacao.Envio.TAmb.Item2, nRec = nRec }; var parametroXml = XmlUtil.Serialize(consultaRecibo, "http://www.portalfiscal.inf.br/nfe"); var node = new XmlDocument(); node.LoadXml(parametroXml); var ambiente = config.IsProducao ? Ambiente.Producao : Ambiente.Homologacao; var codigoUf = (CodigoUfIbge)Enum.Parse(typeof(CodigoUfIbge), _emissorService.GetEmissor().Endereco.UF); try { var servico = _serviceFactory.GetService(modelo, ambiente, Servico.RetAutorizacao, codigoUf, certificado); var client = (NFeRetAutorizacao4SoapClient)servico.SoapClient; var result = client.nfeRetAutorizacaoLote(node); var retorno = (TRetConsReciNFe)XmlUtil.Deserialize<TRetConsReciNFe>(result.OuterXml); return retorno.protNFe.Select(protNFe => new RetornoNotaFiscal { Chave = protNFe.infProt.chNFe, CodigoStatus = protNFe.infProt.cStat, DataAutorizacao = protNFe.infProt.dhRecbto, Motivo = protNFe.infProt.xMotivo, Protocolo = protNFe.infProt.nProt, Xml = XmlUtil.Serialize(protNFe, string.Empty) .Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", string.Empty) .Replace("TProtNFe", "protNFe") .Replace("<infProt xmlns=\"http://www.portalfiscal.inf.br/nfe\">", "<infProt>") }) .ToList(); } catch (Exception e) { log.Error(e); if (!_isFirstTimeRecheckingRecipts) { _isFirstTimeRecheckingRecipts = true; return ConsultarReciboLoteContingencia(nRec, modelo); } _isFirstTimeRecheckingRecipts = false; return null; } }
public ConsultaRecLote2Exception(string message, TConsReciNFe consReciNFe, TRetEnviNFe retEnvNFe, X509Certificate2 cert): base(message) { this.consReciNFe = consReciNFe; this.retEnvNFe = retEnvNFe; this.cert = cert; }
private List <RetornoNotaFiscal> ConsultarReciboLoteContingencia(string nRec, Modelo modelo) { var config = ConfiguracaoService.GetConfiguracao(); X509Certificate2 certificado = null; var certificadoEntity = CertificadoService.GetCertificado(); if (!string.IsNullOrWhiteSpace(certificadoEntity.Caminho)) { certificado = CertificateManager.GetCertificateByPath(certificadoEntity.Caminho, RijndaelManagedEncryption.DecryptRijndael(certificadoEntity.Senha)); } else { certificado = CertificateManager.GetCertificateBySerialNumber(certificadoEntity.NumeroSerial, false); } var consultaRecibo = new TConsReciNFe(); consultaRecibo.versao = "4.00"; consultaRecibo.tpAmb = config.IsProducao ? XmlSchemas.NfeRetAutorizacao.Envio.TAmb.Item1 : XmlSchemas.NfeRetAutorizacao.Envio.TAmb.Item2; consultaRecibo.nRec = nRec; string parametroXML = XmlUtil.Serialize(consultaRecibo, "http://www.portalfiscal.inf.br/nfe"); var node = new XmlDocument(); node.LoadXml(parametroXML); Ambiente ambiente = config.IsProducao ? Ambiente.Producao : Ambiente.Homologacao; var codigoUF = (CodigoUfIbge)Enum.Parse(typeof(CodigoUfIbge), EmissorService.GetEmissor().Endereco.UF); try { var servico = ServiceFactory.GetService(modelo, ambiente, Factory.Servico.RetAutorizacao, codigoUF, certificado); var client = (NFeRetAutorizacao4.NFeRetAutorizacao4SoapClient)servico.SoapClient; var result = client.nfeRetAutorizacaoLote(node); TRetConsReciNFe retorno = (TRetConsReciNFe)XmlUtil.Deserialize <TRetConsReciNFe>(result.OuterXml); List <RetornoNotaFiscal> retornoConsultaList = new List <RetornoNotaFiscal>(); foreach (var protNFe in retorno.protNFe) { var retornoConsultaNota = new RetornoNotaFiscal(); retornoConsultaNota.Chave = protNFe.infProt.chNFe; retornoConsultaNota.CodigoStatus = protNFe.infProt.cStat; retornoConsultaNota.DataAutorizacao = protNFe.infProt.dhRecbto; retornoConsultaNota.Motivo = protNFe.infProt.xMotivo; retornoConsultaNota.Protocolo = protNFe.infProt.nProt; retornoConsultaNota.Xml = XmlUtil.Serialize(protNFe, string.Empty) .Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", string.Empty) .Replace("TProtNFe", "protNFe") .Replace("<infProt xmlns=\"http://www.portalfiscal.inf.br/nfe\">", "<infProt>"); retornoConsultaList.Add(retornoConsultaNota); } return(retornoConsultaList); } catch (Exception) { if (!_isFirstTimeRecheckingRecipts) { _isFirstTimeRecheckingRecipts = true; return(ConsultarReciboLoteContingencia(nRec, modelo)); } else { _isFirstTimeRecheckingRecipts = false; return(null); } } }