Ejemplo n.º 1
0
        public void EnviarXml(XmlDocument doc, X509Certificate2 cert, ref Entidade_Cancelamento obj)
        {
            try
            {
                object retObj = new object();
                UrlEstados = new UrlNfesEstados();

                RecepcaoEvento.RecepcaoEvento RecepEvCanc = new RecepcaoEvento.RecepcaoEvento();
                RecepcaoEvento.nfeCabecMsg    wCabMsg     = new nfeCabecMsg();

                wCabMsg.cUF         = obj.cUf.ToString();
                wCabMsg.versaoDados = "1.00";

                RecepEvCanc.SoapVersion     = System.Web.Services.Protocols.SoapProtocolVersion.Soap12;
                RecepEvCanc.PreAuthenticate = true;
                RecepEvCanc.ClientCertificates.Add(cert);
                RecepEvCanc.nfeCabecMsgValue = wCabMsg;

                nodeList        = doc.GetElementsByTagName("envEvento");
                nodeStatus      = nodeList.Item(0);
                RecepEvCanc.Url = UrlEstados.SetarUrlEstado(UrlEstados.Uf(int.Parse(obj.cUf.ToString())), obj.TpAmb == "HOM" ? UrlNfesEstados.tbAmbiente.HOM : UrlNfesEstados.tbAmbiente.PROD, UrlNfesEstados.TipoUrlEnvio.RecepcaoEvento);
                retObj          = RecepEvCanc.nfeRecepcaoEvento(nodeStatus);
                DeserilizarEvento(retObj, ref obj);
            }
            catch (Exception Ex)
            {
                Mensagem.MensagemErro(Mensagem.TipoMensagem.RetAutoriz, "Saida", Ex.Message.ToString());
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
        public RetornoSimples NfeInutilizacaoNF2(NFeEletronica.Consulta.Inutilizacao inutilizacao)
        {
            var webservice = new NfeInutilizacao2();
            var cabecalho  = new nfeCabecMsg();

            cabecalho.cUF         = "35";
            cabecalho.versaoDados = NFeContexto.Versao.VersaoString;

            var id = "ID" + inutilizacao.UF + inutilizacao.Ano + inutilizacao.CNPJ +
                     Int32.Parse(inutilizacao.Mod).ToString("D2") + Int32.Parse(inutilizacao.Serie).ToString("D3") +
                     Int32.Parse(inutilizacao.NumeroNfeInicial).ToString("D9") +
                     Int32.Parse(inutilizacao.NumeroNfeFinal).ToString("D9");
            //Monta corpo do xml de envio
            var xmlString = new StringBuilder();

            xmlString.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            xmlString.Append("<inutNFe xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"2.00\">");
            xmlString.Append("<infInut Id=\"" + id + "\">");
            xmlString.Append("    <tpAmb>" + (NFeContexto.Producao ? "1" : "2") + "</tpAmb>");
            xmlString.Append("    <xServ>INUTILIZAR</xServ>");
            xmlString.Append("    <cUF>" + inutilizacao.UF + "</cUF>");
            xmlString.Append("    <ano>" + inutilizacao.Ano + "</ano>");
            xmlString.Append("    <CNPJ>" + inutilizacao.CNPJ + "</CNPJ>");
            xmlString.Append("    <mod>" + inutilizacao.Mod + "</mod>");
            xmlString.Append("    <serie>" + inutilizacao.Serie + "</serie>");
            xmlString.Append("    <nNFIni>" + inutilizacao.NumeroNfeInicial + "</nNFIni>");
            xmlString.Append("    <nNFFin>" + inutilizacao.NumeroNfeFinal + "</nNFFin>");
            xmlString.Append("    <xJust>" + inutilizacao.Justificativa + "</xJust>");
            xmlString.Append("</infInut>");
            xmlString.Append("</inutNFe>");


            var assinado = Assinar(xmlString, id);

            webservice.nfeCabecMsgValue = cabecalho;
            var resultado = webservice.nfeInutilizacaoNF2(assinado);


            var status = resultado["cStat"].InnerText;
            var motivo = resultado["xMotivo"].InnerText;

            return(new RetornoSimples(status, motivo));
        }
Ejemplo n.º 4
0
        public Retorno.Recepcao Enviar(long numeroLote, String cUF)
        {
            var nfeRecepcao2 = new NfeRecepcao2.NfeRecepcao2();
            var nfeCabecalho = new nfeCabecMsg();

            //Informa dados no WS de cabecalho
            nfeCabecalho.cUF         = cUF;
            nfeCabecalho.versaoDados = NFeContexto.Versao.VersaoString;

            nfeRecepcao2.nfeCabecMsgValue = nfeCabecalho;
            nfeRecepcao2.ClientCertificates.Add(NFeContexto.Certificado);

            //Envia para o webservice e recebe a resposta
            var xmlResposta = nfeRecepcao2.nfeRecepcaoLote2(MontarXml(numeroLote).DocumentElement);

            var recibo = xmlResposta["infRec"]["nRec"].InnerText;
            var motivo = xmlResposta["xMotivo"].InnerText;

            return(new Retorno.Recepcao(recibo, "", motivo));
        }
Ejemplo n.º 5
0
        public System.Threading.Tasks.Task <nfeConsulta3NFResponse> nfeConsultaNFAsync(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
        {
            nfeConsulta3NFRequest inValue = new nfeConsulta3NFRequest();

            inValue.nfeCabecMsg = nfeCabecMsg;
            inValue.nfeDadosMsg = nfeDadosMsg;
            return(((NfeConsulta3Soap12)(this.Channel)).nfeConsultaNFAsync(inValue));
        }
Ejemplo n.º 6
0
 public recepcaoEPECRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeDadosMsg = nfeDadosMsg;
 }
Ejemplo n.º 7
0
 public consultaCadastro2Response(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode consultaCadastro2Result)
 {
     this.nfeCabecMsg             = nfeCabecMsg;
     this.consultaCadastro2Result = consultaCadastro2Result;
 }
Ejemplo n.º 8
0
 public consultaCadastro2Request(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeDadosMsg = nfeDadosMsg;
 }
Ejemplo n.º 9
0
 public nfeInutilizacaoNF2Request(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeDadosMsg = nfeDadosMsg;
 }
Ejemplo n.º 10
0
 public nfeStatusServicoNFRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeDadosMsg = nfeDadosMsg;
 }
Ejemplo n.º 11
0
 public nfeRecepcaoEventoResponse(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeRecepcaoEventoResult)
 {
     this.nfeCabecMsg             = nfeCabecMsg;
     this.nfeRecepcaoEventoResult = nfeRecepcaoEventoResult;
 }
Ejemplo n.º 12
0
        public System.Threading.Tasks.Task <nfeAutorizacao3LoteResponse> nfeAutorizacaoLoteZipAsync(nfeCabecMsg nfeCabecMsg, string nfeDadosMsgZip)
        {
            nfeAutorizacao3LoteZipRequest inValue = new nfeAutorizacao3LoteZipRequest();

            inValue.nfeCabecMsg    = nfeCabecMsg;
            inValue.nfeDadosMsgZip = nfeDadosMsgZip;
            return(((NfeAutorizacao3Soap12)(this.Channel)).nfeAutorizacaoLoteZipAsync(inValue));
        }
Ejemplo n.º 13
0
 public nfeStatusServicoNFResponse(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeStatusServicoNFResult)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeStatusServicoNFResult = nfeStatusServicoNFResult;
 }
Ejemplo n.º 14
0
 public nfeAutorizacao3LoteZipRequest(nfeCabecMsg nfeCabecMsg, string nfeDadosMsgZip)
 {
     this.nfeCabecMsg    = nfeCabecMsg;
     this.nfeDadosMsgZip = nfeDadosMsgZip;
 }
Ejemplo n.º 15
0
        public System.Threading.Tasks.Task <nfeStatusServicoNF2Response> nfeStatusServicoNF2Async(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
        {
            nfeStatusServicoNF2Request inValue = new nfeStatusServicoNF2Request();

            inValue.nfeCabecMsg = nfeCabecMsg;
            inValue.nfeDadosMsg = nfeDadosMsg;
            return(((NfeStatusServico2Soap12)(this.Channel)).nfeStatusServicoNF2Async(inValue));
        }
Ejemplo n.º 16
0
        public Retorno.RetRecepcao Enviar(String numeroRecibo, String cUF)
        {
            //Monta corpo do xml de envio
            var xmlString = new StringBuilder();

            xmlString.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            xmlString.Append("<consReciNFe xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"" +
                             NFeContexto.Versao.VersaoString + "\">");
            xmlString.Append("    <tpAmb>" + (NFeContexto.Producao ? "1" : "2") + "</tpAmb>");
            xmlString.Append("    <nRec>" + numeroRecibo + "</nRec>");
            xmlString.Append("</consReciNFe>");

            XmlNode consultaXml = Xml.StringToXml(xmlString.ToString());


            var nfeRetRecepcao2 = new NfeRetRecepcao2.NfeRetRecepcao2();
            var nfeCabecalho    = new nfeCabecMsg();

            //Informa dados no WS de cabecalho
            nfeCabecalho.cUF         = cUF;
            nfeCabecalho.versaoDados = NFeContexto.Versao.VersaoString;

            nfeRetRecepcao2.nfeCabecMsgValue = nfeCabecalho;
            nfeRetRecepcao2.ClientCertificates.Add(NFeContexto.Certificado);


            Retorno.RetRecepcao retorno;
            XmlNode             respostaXml = null;

            var isEmProcessamento = true;

            //Verifica a resposta de envio da sefaz e aguarda até quando estiver processado
            do
            {
                respostaXml = nfeRetRecepcao2.nfeRetRecepcao2(consultaXml);

                //Esse e o resultado só do lote (cabeçalho)
                var status = respostaXml["cStat"].InnerText;
                var motivo = respostaXml["xMotivo"].InnerText;
                retorno = new Retorno.RetRecepcao("", "", status, motivo);

                if (retorno.Status != "105")
                {
                    isEmProcessamento = false;
                }
                else
                {
                    Thread.Sleep(5000);
                }
            } while (isEmProcessamento);


            if (retorno.Status != "225")
            {
                //Isso aqui é o resultado de CADA NFe, mas como por enquanto pra cada lote só manda 1 nota, entao segue assim por enquanto #todo
                if (retorno.Status != "100" && retorno.Status != "104")
                {
                    throw new Exception("Lote não processado: " + retorno.Status + " - " + retorno.Motivo);
                }
                var protocolo = "";
                var status    = "";
                var motivo    = "";

                try
                {
                    status    = respostaXml["protNFe"]["infProt"]["cStat"].InnerText;
                    protocolo = respostaXml["protNFe"]["infProt"]["nProt"].InnerText;
                    motivo    = respostaXml["protNFe"]["infProt"]["xMotivo"].InnerText;
                }
                catch
                {
                    //ignora o erro
                }

                //Caso deu algum problema e nao veio o protocolo, mas veio a descrição do problema
                if (String.IsNullOrEmpty(protocolo) && (!String.IsNullOrEmpty(status) && !String.IsNullOrEmpty(motivo)))
                {
                    throw new Exception("Erro de retorno: " + status + " - " + motivo);
                }

                try
                {
                    var numeroNota = respostaXml["protNFe"]["infProt"]["chNFe"].InnerText;
                    protocolo = respostaXml["protNFe"]["infProt"]["nProt"].InnerText;
                    status    = respostaXml["protNFe"]["infProt"]["cStat"].InnerText;
                    motivo    = respostaXml["protNFe"]["infProt"]["xMotivo"].InnerText;

                    return(new Retorno.RetRecepcao(numeroNota, protocolo, status, motivo));
                }
                catch (Exception e)
                {
                    throw new Exception("Erro ler resposta de envio: " + e.Message);
                }
            }
            throw new Exception("Erro ao enviar lote XML: " + retorno.Motivo);
        }
Ejemplo n.º 17
0
 public nfeConsulta3NFRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeDadosMsg = nfeDadosMsg;
 }
Ejemplo n.º 18
0
 public nfeRecepcaoEventoRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeDadosMsg = nfeDadosMsg;
 }
Ejemplo n.º 19
0
 public nfeConsulta3NFResponse(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeConsultaNFResult)
 {
     this.nfeCabecMsg         = nfeCabecMsg;
     this.nfeConsultaNFResult = nfeConsultaNFResult;
 }
Ejemplo n.º 20
0
        public System.Threading.Tasks.Task <nfeRetAutorizacaoLoteResponse> nfeRetAutorizacaoLoteAsync(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
        {
            nfeRetAutorizacaoLoteRequest inValue = new nfeRetAutorizacaoLoteRequest
            {
                nfeCabecMsg = nfeCabecMsg,
                nfeDadosMsg = nfeDadosMsg
            };

            return(((NfeRetAutorizacaoSoap12)(this.Channel)).nfeRetAutorizacaoLoteAsync(inValue));
        }
Ejemplo n.º 21
0
        public System.Threading.Tasks.Task <nfeRecepcaoEventoResponse> nfeRecepcaoEventoAsync(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
        {
            nfeRecepcaoEventoRequest inValue = new nfeRecepcaoEventoRequest();

            inValue.nfeCabecMsg = nfeCabecMsg;
            inValue.nfeDadosMsg = nfeDadosMsg;
            return(((RecepcaoEventoSoap12)(this.Channel)).nfeRecepcaoEventoAsync(inValue));
        }
Ejemplo n.º 22
0
 public nfeInutilizacaoNF2Response(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeInutilizacaoNF2Result)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeInutilizacaoNF2Result = nfeInutilizacaoNF2Result;
 }
Ejemplo n.º 23
0
 public nfeRetAutorizacaoLoteResponse(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeRetAutorizacaoLoteResult)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeRetAutorizacaoLoteResult = nfeRetAutorizacaoLoteResult;
 }
Ejemplo n.º 24
0
        public System.Threading.Tasks.Task <consultaCadastro2Response> consultaCadastro2Async(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
        {
            consultaCadastro2Request inValue = new consultaCadastro2Request();

            inValue.nfeCabecMsg = nfeCabecMsg;
            inValue.nfeDadosMsg = nfeDadosMsg;
            return(((CadConsultaCadastro2Soap12)(this.Channel)).consultaCadastro2Async(inValue));
        }
Ejemplo n.º 25
0
 public nfeRetAutorizacaoLoteRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeDadosMsg = nfeDadosMsg;
 }
Ejemplo n.º 26
0
 public nfeDownloadNFRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg)
 {
     this.nfeCabecMsg = nfeCabecMsg;
     this.nfeDadosMsg = nfeDadosMsg;
 }