Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. web.Method = "POST";
  2. web.ContentType = "text/xml;charset=utf-8";
  3. web.Accept = "text/xml";
  4. web.Headers.Clear();
  5. web.Headers.Add("SOAPAction", url);
  6.  
  7. X509Certificate2 certificado = ObterCertificado();
  8. if (certificado != null)
  9. {
  10. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
  11. web.ClientCertificates.Add(certificado);
  12. }
  13.  
  14. var soap = "<?xml version='1.0' encoding='UTF-8'?>";
  15. soap += "<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>";
  16. soap += "<soap12:Body>";
  17. soap += " <cteDistDFeInteresse xmlns='http://www.portalfiscal.inf.br/cte/wsdl/CTeDistribuicaoDFe'>";
  18. soap += " <distDFeInt xmlns='http://www.portalfiscal.inf.br/cte' versao='1.00'>";
  19. soap += " <tpAmb>1</tpAmb>";
  20. soap += " <cUFAutor>91</cUFAutor>";
  21. soap += " <CNPJ>00000000000000</CNPJ>";
  22. soap += " <distNSU><ultNSU>000000000000000</ultNSU></distNSU>";
  23. soap += " </distDFeInt>";
  24. soap += " </cteDistDFeInteresse>";
  25. soap += "</soap12:Body>";
  26. soap += "</soap12:Envelope>";
  27.  
  28. // soap = "<cteDadosMsg><distDFeInt xmlns='http://www.portalfiscal.inf.br/nfe' versao='1.00'><tpAmb>1</tpAmb><cUFAutor>35</cUFAutor><CNPJ>000000000000000</CNPJ><distNSU><ultNSU>000000000000002</ultNSU></distNSU></distDFeInt></cteDadosMsg>";
  29.  
  30. var byteArray = Encoding.UTF8.GetBytes(soap);
  31. web.ContentLength = byteArray.Length;
  32. using (var stream = web.GetRequestStream())
  33. {
  34. stream.Write(byteArray, 0, byteArray.Length);
  35. }
  36.  
  37. using (var webResponse = (HttpWebResponse)web.GetResponse())
  38. {
  39. using (var stream = webResponse.GetResponseStream())
  40. {
  41. retorno = new StreamReader(stream).ReadToEnd();
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement