Problems sending Nfe 4.0 to the states of SP, MT and MS

0

I'm having trouble sending NFe 4.0 down only to the SP, MT, and MS states. Others are shipping normally.

You're giving this section an error:

HttpWebResponse responsePost = (HttpWebResponse)httpPostConsultaNFe.GetResponse();

Here is the code that sends it:

public string RequestWebService4_0(ConfiguracaoWebService configuracaoWebService, string param, string action, X509Certificate2 certificado, int tempoLimiteSefaz)
    {
        Uri urlpost = new Uri(configuracaoWebService.CaminhoServico);
        HttpWebRequest httpPostConsultaNFe = (HttpWebRequest)HttpWebRequest.Create(urlpost);

        string postConsultaComParametros = param;
        byte[] buffer2 = Encoding.ASCII.GetBytes(postConsultaComParametros);


        httpPostConsultaNFe.CookieContainer = cookies;
        tempoLimiteSefaz = tempoLimiteSefaz * 3000;
        httpPostConsultaNFe.Timeout = tempoLimiteSefaz;
        //httpPostConsultaNFe.ContentType = configuracaoWebService.ContentType;
        httpPostConsultaNFe.Headers.Add(@"SOAP:Action");
        httpPostConsultaNFe.ContentType = "text/xml;charset=\"utf-8\"";
        httpPostConsultaNFe.Accept = "text/xml";
        httpPostConsultaNFe.Method = "POST";
        httpPostConsultaNFe.ClientCertificates.Add(certificado);

        X509Certificate serverCert = X509Certificate.CreateFromCertFile(@"C:\PCInfo\certificado.pem");
        httpPostConsultaNFe.ClientCertificates.Add(serverCert);
        httpPostConsultaNFe.ServicePoint.Expect100Continue = true;
        httpPostConsultaNFe.ProtocolVersion = HttpVersion.Version11;
        httpPostConsultaNFe.AllowWriteStreamBuffering = true;


        //if (configuracaoWebService.CaminhoServico.Contains("Autorizacao4") || configuracaoWebService.CaminhoServico.Contains("autorizacao4"))
        httpPostConsultaNFe.Headers.Add("soapaction", action);

        //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
        //ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.DefaultConnectionLimit = 9999;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        Stream PostData = httpPostConsultaNFe.GetRequestStream();
        PostData.Write(buffer2, 0, buffer2.Length);
        PostData.Close();

        HttpWebResponse responsePost = (HttpWebResponse)httpPostConsultaNFe.GetResponse();
        Stream istreamPost = responsePost.GetResponseStream();
        var strRespotaUrlConsultaNFe = new StreamReader(istreamPost, System.Text.Encoding.UTF8);

        return strRespotaUrlConsultaNFe.ReadToEnd();
    }
    
asked by anonymous 04.12.2018 / 17:03

0 answers