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()); } }
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)); }
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)); }
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)); }
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)); }
public recepcaoEPECRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg) { this.nfeCabecMsg = nfeCabecMsg; this.nfeDadosMsg = nfeDadosMsg; }
public consultaCadastro2Response(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode consultaCadastro2Result) { this.nfeCabecMsg = nfeCabecMsg; this.consultaCadastro2Result = consultaCadastro2Result; }
public consultaCadastro2Request(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg) { this.nfeCabecMsg = nfeCabecMsg; this.nfeDadosMsg = nfeDadosMsg; }
public nfeInutilizacaoNF2Request(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg) { this.nfeCabecMsg = nfeCabecMsg; this.nfeDadosMsg = nfeDadosMsg; }
public nfeStatusServicoNFRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg) { this.nfeCabecMsg = nfeCabecMsg; this.nfeDadosMsg = nfeDadosMsg; }
public nfeRecepcaoEventoResponse(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeRecepcaoEventoResult) { this.nfeCabecMsg = nfeCabecMsg; this.nfeRecepcaoEventoResult = nfeRecepcaoEventoResult; }
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)); }
public nfeStatusServicoNFResponse(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeStatusServicoNFResult) { this.nfeCabecMsg = nfeCabecMsg; this.nfeStatusServicoNFResult = nfeStatusServicoNFResult; }
public nfeAutorizacao3LoteZipRequest(nfeCabecMsg nfeCabecMsg, string nfeDadosMsgZip) { this.nfeCabecMsg = nfeCabecMsg; this.nfeDadosMsgZip = nfeDadosMsgZip; }
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)); }
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); }
public nfeConsulta3NFRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg) { this.nfeCabecMsg = nfeCabecMsg; this.nfeDadosMsg = nfeDadosMsg; }
public nfeRecepcaoEventoRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg) { this.nfeCabecMsg = nfeCabecMsg; this.nfeDadosMsg = nfeDadosMsg; }
public nfeConsulta3NFResponse(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeConsultaNFResult) { this.nfeCabecMsg = nfeCabecMsg; this.nfeConsultaNFResult = nfeConsultaNFResult; }
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)); }
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)); }
public nfeInutilizacaoNF2Response(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeInutilizacaoNF2Result) { this.nfeCabecMsg = nfeCabecMsg; this.nfeInutilizacaoNF2Result = nfeInutilizacaoNF2Result; }
public nfeRetAutorizacaoLoteResponse(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeRetAutorizacaoLoteResult) { this.nfeCabecMsg = nfeCabecMsg; this.nfeRetAutorizacaoLoteResult = nfeRetAutorizacaoLoteResult; }
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)); }
public nfeRetAutorizacaoLoteRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg) { this.nfeCabecMsg = nfeCabecMsg; this.nfeDadosMsg = nfeDadosMsg; }
public nfeDownloadNFRequest(nfeCabecMsg nfeCabecMsg, System.Xml.XmlNode nfeDadosMsg) { this.nfeCabecMsg = nfeCabecMsg; this.nfeDadosMsg = nfeDadosMsg; }