public static string Construir(DFeSoapConfig soapConfig) { StringBuilder env = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); env.Append("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "); env.Append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "); env.Append("xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"); // cabecalho env.Append("<soap12:Header>"); env.Append(soapConfig.DFeCabecalho.GetXmlHeader()); env.Append("</soap12:Header>"); // corpo env.Append("<soap12:Body>"); env.Append(soapConfig.DFeCorpo.GetXmlBody()); env.Append("</soap12:Body>"); env.Append("</soap12:Envelope>"); return(env.ToString()); }
public static string EnviaSefaz(DFeSoapConfig soapConfig) { string XMLRetorno = string.Empty; string xmlSoap = Envelope.Construir(soapConfig); Uri uri = new Uri(soapConfig.Url); WebRequest webRequest = WebRequest.Create(uri); HttpWebRequest httpWR = (HttpWebRequest)webRequest; httpWR.Timeout = soapConfig.TimeOut == 0 ? 2000 : soapConfig.TimeOut; httpWR.ContentLength = Encoding.UTF8.GetBytes(xmlSoap).Length; httpWR.ClientCertificates.Add(soapConfig.Certificado); httpWR.ComposeContentType("application/soap+xml", Encoding.UTF8, soapConfig.Metodo); httpWR.Method = "POST"; Stream reqStream = httpWR.GetRequestStream(); StreamWriter streamWriter = new StreamWriter(reqStream); streamWriter.Write(xmlSoap, 0, Encoding.UTF8.GetBytes(xmlSoap).Length); streamWriter.Close(); WebResponse webResponse = httpWR.GetResponse(); Stream respStream = webResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(respStream); XMLRetorno = streamReader.ReadToEnd(); return(XMLRetorno); }
public NFeAutorizacao4(string url, X509Certificate certificado, int timeOut, bool compactarMensagem, DFe.Classes.Flags.VersaoServico versaoNfeAutorizacao, Estado estado) { SoapConfig = new DFeSoapConfig { DFeCorpo = new DFeCorpo("http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4", new NfeTagCorpo(estado.GetParametroDeEntradaWsdl(compactarMensagem))), DFeCabecalho = new DFeCabecalho(estado, versaoNfeAutorizacao, new TagCabecalhoVazia(), "http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4"), Metodo = compactarMensagem ? "http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4/nfeAutorizacaoLoteZIP" : "http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4/nfeAutorizacaoLote", Url = url, Certificado = new X509Certificate2(certificado), TimeOut = timeOut }; }
/// <summary> /// Cria o cliente <see cref="SoapHttpClientProtocol"/> para o serviço de Autorização /// </summary> /// <param name="cfg">Configuração do serviço</param> /// <param name="certificado">Certificado</param> /// <returns></returns> public static INfeServicoAutorizacao CriaWsdlAutorizacao(ConfiguracaoServico cfg, X509Certificate2 certificado, bool compactarMensagem) { var url = Enderecador.ObterUrlServico(ServicoNFe.NFeAutorizacao, cfg); if (cfg.UsaSvanNFe4(cfg.VersaoNFeAutorizacao)) { return(new NFeAutorizacao4SVAN(url, certificado, cfg.TimeOut)); } if (cfg.UsaSvcanNFe4(cfg.VersaoNFeAutorizacao)) { return(new NFeAutorizacao4SVCAN(url, certificado, cfg.TimeOut)); } if (cfg.VersaoNFeAutorizacao == VersaoServico.ve400) { DFeSoapConfig soapConfig = new DFeSoapConfig { DFeCorpo = new DFeCorpo("http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4", new NfeTagCorpo(cfg.cUF.GetParametroDeEntradaWsdl(compactarMensagem))), DFeCabecalho = new DFeCabecalho(cfg.cUF, ConverteVersaoLayout(cfg.VersaoNFeAutorizacao), new TagCabecalhoVazia(), "http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4"), Metodo = compactarMensagem ? "http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4/nfeAutorizacaoLoteZIP" : "http://www.portalfiscal.inf.br/nfe/wsdl/NFeAutorizacao4/nfeAutorizacaoLote", Url = url, Certificado = certificado, TimeOut = cfg.TimeOut }; return(new NFeAutorizacao4(soapConfig)); } if (cfg.cUF == Estado.PR & cfg.VersaoNFeAutorizacao == VersaoServico.ve310) { return(new NfeAutorizacao3(url, certificado, cfg.TimeOut)); } return(new NfeAutorizacao(url, certificado, cfg.TimeOut)); }
protected string Invoke(DFeSoapConfig soapConfig) { return(RequestWS.EnviaSefaz(soapConfig)); }
public NFeAutorizacao4(DFeSoapConfig soapConfig) { SoapConfig = soapConfig; }