Emission of NF-e 4.0: Goiás (C#/.Net)

Asked

Viewed 304 times

1

I am updating the communication of NF-e for some customers and in general I am not having problems for authorizers like Rio Grande do Sul and São Paulo, for example.

But I’m not getting Goiás to work at all.

Namely, I made a simple Application Console, in which I inserted a Referral service for the Nfe Authorization service of Goiás (requires digital certificate):

https://homolog.sefaz.go.gov.br/nfe/services/NFeAutorizacao4?wsdl

The error happens whenever I call the remote method "nfeAuthorization": System.ServiceModel.Security.Securitynegotiationexception: 'It was not possible to establish a secure channel for SSL/TLS with authority 'Homolog.sefaz.go.gov.br'.'

Namely: the certificate chain is properly installed.

Cadeia de certificados

One thing I found strange is that although the wsdl is on an HTTPS, the endpoint solved by the service is http.

<client>
   <endpoint address="http://homolog.sefaz.go.gov.br:80/nfe/services/NFeAutorizacao4"
            binding="customBinding" bindingConfiguration="NFeAutorizacao4ServiceBinding"
            contract="Hom.Goias.NFeAutorizacao4Service" name="NFeAutorizacao4Port" />
</client>

If I force https, my mistake is timeout.

My code goes below:

    static void Main(string[] args)
    {
        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

        var client = new Hom.Goias.NFeAutorizacao4ServiceClient();


        client.ClientCredentials.ClientCertificate.Certificate =
            new System.Security.Cryptography.X509Certificates.X509Certificate2(@"D:\Projects\XPTO\CERT.pfx", "SENHADOCERTIFICADO");


        var xdoc = new XmlDocument();

        xdoc.Load(@"d:\Projects\XPTO\nfe-go.xml");

        var resp = client.nfeAutorizacaoLote(xdoc);

        Console.ReadKey();


    }

Any suggestion is welcome!

1 answer

0


I got!

In the end it was more a matter of adjusting the same bindings!

When I change the address to "https" I need to take out port 80. Also, I had to add some information about the transport. But in the end, it worked!

<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="NFeAutorizacao4ServiceBinding">
          <textMessageEncoding messageVersion="Soap12" />
          <httpsTransport authenticationScheme="Digest" requireClientCertificate="true"/>
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://homolog.sefaz.go.gov.br/nfe/services/NFeAutorizacao4"
          binding="customBinding" bindingConfiguration="NFeAutorizacao4ServiceBinding"
          contract="Hom.Goias.NFeAutorizacao4Service" name="NFeAutorizacao4Port" />
    </client>
  </system.serviceModel>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.