Error in the use of WS from the IRS, (Rejection: Use only the standard NF-e namespace)

Asked

Viewed 1,515 times

1

Hello! I am trying to access the SOAP service of approval of the IRS to run the service status query, I have made all possible combinations (including those present in the last manual published) in the construction of request SOAP and unsuccessful message data, below the resources and test results:

WSDL used for the construction of SOAP client (origin: https://homologacao.nfe.fazenda.sp.gov.br/ws/nfestatusservico2.asmx?WSDL):

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Serviço destinado à consulta do status do serviço prestado pelo Portal da Secretaria de Fazenda Estadual.</wsdl:documentation>
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
      <s:element name="nfeDadosMsg">
        <s:complexType mixed="true">
          <s:sequence>
            <s:any />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="nfeStatusServicoNF2Result">
        <s:complexType mixed="true">
          <s:sequence>
            <s:any />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="nfeCabecMsg" type="tns:nfeCabecMsg" />
      <s:complexType name="nfeCabecMsg">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="cUF" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="versaoDados" type="s:string" />
        </s:sequence>
        <s:anyAttribute />
      </s:complexType>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="nfeStatusServicoNF2Soap12In">
    <wsdl:part name="nfeDadosMsg" element="tns:nfeDadosMsg" />
  </wsdl:message>
  <wsdl:message name="nfeStatusServicoNF2Soap12Out">
    <wsdl:part name="nfeStatusServicoNF2Result" element="tns:nfeStatusServicoNF2Result" />
  </wsdl:message>
  <wsdl:message name="nfeStatusServicoNF2nfeCabecMsg">
    <wsdl:part name="nfeCabecMsg" element="tns:nfeCabecMsg" />
  </wsdl:message>
  <wsdl:portType name="NfeStatusServico2Soap12">
    <wsdl:operation name="nfeStatusServicoNF2">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Consulta Status do Serviço</wsdl:documentation>
      <wsdl:input message="tns:nfeStatusServicoNF2Soap12In" />
      <wsdl:output message="tns:nfeStatusServicoNF2Soap12Out" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="NfeStatusServico2Soap12" type="tns:NfeStatusServico2Soap12">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="nfeStatusServicoNF2">
      <soap12:operation soapAction="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2/nfeStatusServicoNF2" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
        <soap12:header message="tns:nfeStatusServicoNF2nfeCabecMsg" part="nfeCabecMsg" use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
        <soap12:header message="tns:nfeStatusServicoNF2nfeCabecMsg" part="nfeCabecMsg" use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="NfeStatusServico2">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Serviço destinado à consulta do status do serviço prestado pelo Portal da Secretaria de Fazenda Estadual.</wsdl:documentation>
    <wsdl:port name="NfeStatusServico2Soap12" binding="tns:NfeStatusServico2Soap12">
      <soap12:address location="https://homologacao.nfe.fazenda.sp.gov.br/ws/nfestatusservico2.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

SOAP request generated:

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:tns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2"
                 xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
    <soap12:Header>
        <nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <versaoDados>3.10</versaoDados>
            <cUF>35</cUF>
        </nfeCabecMsg>
    </soap12:Header>
    <soap12:Body>
        <nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <consStatServ versao="3.10">
                <cUF>35</cUF>
                <tpAmb>2</tpAmb>
                <xServ>STATUS</xServ>
            </consStatServ>
        </nfeDadosMsg>
    </soap12:Body>
</soap12:Envelope>

XML of the message:

<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
    <consStatServ versao="3.10">
        <cUF>35</cUF>
        <tpAmb>2</tpAmb>
        <xServ>STATUS</xServ>
    </consStatServ>
</nfeDadosMsg>

XML response from request:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <cUF>35</cUF>
            <versaoDados>3.10</versaoDados>
        </nfeCabecMsg>
    </soap:Header>
    <soap:Body>
        <nfeStatusServicoNF2Result xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <retConsStatServ versao="3.10" xmlns="http://www.portalfiscal.inf.br/nfe">
                <tpAmb>2</tpAmb>
                <verAplic>SP_NFE_PL_008i2</verAplic>
                <cStat>587</cStat>
                <xMotivo>Rejeição: Usar somente o namespace padrão da NF-e</xMotivo>
                <cUF>35</cUF>
                <dhRecbto>0001-01-01T00:00:00+00:00</dhRecbto>
            </retConsStatServ>
        </nfeStatusServicoNF2Result>
    </soap:Body>
</soap:Envelope>

In attempts to solve the problem by inferring that the namespaces additional in the evelope SOAP were the cause, I built the request with the same namespaces of the answer, changing from:

<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:tns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2"
                 xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">

for:

<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" 
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema">

But I did not succeed. Anyway, if someone here has faced this problem and can share the solution would be great!

Technologies used:

Nodejs

Node-Soap (github.com/vpulim/Node-Soap)

Call code for WS:

        var url = __server_settings.nfe.wsdl[__server_settings.nfe.environments.STAGING].service_status;

        var options = {
            envelopeKey: 'soap12',
            forceSoap12Headers: true
        }

        soap.createClient(url, options, function(err, client) {
            pfx_utils.extractPfxInfo(path.resolve(__server_settings.paths.CERTIFICATES, 'certificate.pfx'), '<password>', function (err, results, key, certificate) {
                if (err == null) {

                    client.setSecurity(new soap.ClientSSLSecurity(key, certificate));

                    var header = {
                        nfeCabecMsg: {
                            attributes: {
                                xmlns: 'http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2'
                            },
                            versaoDados: '3.10',
                            cUF: 35
                        }
                    };
                    client.addSoapHeader(header);

                    var data = {
                        consStatServ: {
                            attributes: {
                                versao: '3.10',
                                xmlns: 'http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2'
                            },
                            cUF: 35,
                            tpAmb: 2,
                            xServ: 'STATUS'
                        }
                    }

                    client.nfeStatusServicoNF2(data, function(err, result) {
                        console.log(result);
                    });
                } else {
                    console.log(__('Error extracting data from certificate!'));
                }
            });
        });

Grateful!

Paulo Eduardo Ferreira Ventura

1 answer

2


Finally solved, the correct XML:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:tns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2"
               xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
    <soap:Header>
        <nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <cUF>35</cUF>
            <versaoDados>3.10</versaoDados>
        </nfeCabecMsg>
    </soap:Header>
    <soap:Body>
        <nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <consStatServ versao="3.10" xmlns="http://www.portalfiscal.inf.br/nfe">
                <tpAmb>2</tpAmb>
                <cUF>35</cUF>
                <xServ>STATUS</xServ>
            </consStatServ>
        </nfeDadosMsg>
    </soap:Body>
</soap:Envelope>

XML INCORRECT:

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:tns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2"
                 xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
    <soap12:Header>
        <nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <versaoDados>3.10</versaoDados>
            <cUF>35</cUF>
        </nfeCabecMsg>
    </soap12:Header>
    <soap12:Body>
        <nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
            <consStatServ versao="3.10">
                <cUF>35</cUF>
                <tpAmb>2</tpAmb>
                <xServ>STATUS</xServ>
            </consStatServ>
        </nfeDadosMsg>
    </soap12:Body>
</soap12:Envelope>

What caused the request to fail was the order of the properties arranged in the SOAP envelope header, the orders of the data area properties of the message and the namespace of tag consStatServ that had not been informed. The error presented guided me to look for the problem relating it only to namespaces (Rejection: Use only the standard NF-e namespace), and was complaining about the frustration with a co-worker that I was attacked to check the order of the properties in the data areas of the SOAP request.

Erroneous SOAP header:

<soap:Header>
    <nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
        <cUF>35</cUF>
        <versaoDados>3.10</versaoDados>
    </nfeCabecMsg>
</soap:Header>

SOAP header CORRECT:

<soap12:Header>
    <nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
        <versaoDados>3.10</versaoDados>
        <cUF>35</cUF>
    </nfeCabecMsg>
</soap12:Header>

Data from wrong message:

<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
    <consStatServ versao="3.10">
        <cUF>35</cUF>
        <tpAmb>2</tpAmb>
        <xServ>STATUS</xServ>
    </consStatServ>
</nfeDadosMsg>

Message data CORRECT:

<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
    <consStatServ versao="3.10" xmlns="http://www.portalfiscal.inf.br/nfe">
        <tpAmb>2</tpAmb>
        <cUF>35</cUF>
        <xServ>STATUS</xServ>
    </consStatServ>
</nfeDadosMsg>

I could have validated XML using the schema provided by SEFAZ, but like request is built dynamically by the API I am using this was not possible.

The End! And may no one else in the world suffer from positions of elements in an XML!

SOAP XML Property Order is Important

Browser other questions tagged

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