Error 242 when consuming NfeDownloadNF

3

I'm trying to consume the NFE download service on the farm:

https://www.sefazvirtual.fazenda.gov.br/NfeDownloadNF/NfeDownloadNF.asmx

But I have gotten the following error:

  

ERROR: 242   Reason: Rejection: nfeCabecMsg element missing from SOAP Header

<?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:Body>
        <nfeDownloadNFResult xmlns=\"http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF\">
            <retDownloadNFe versao=\"1.00\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">
                <tpAmb>1</tpAmb>
                <verAplic>SVAN_2.1.1</verAplic>
                <cStat>242</cStat>
                <xMotivo>Rejeicao: Elemento nfeCabecMsg inexistente no SOAP Header</xMotivo>
                <dhResp>2015-11-03T12:18:06</dhResp>
            </retDownloadNFe>
        </nfeDownloadNFResult>
    </soap:Body>
</soap:Envelope>

The error is peculiar because as you can see in the message below the header structure is in the message.

The message I have sent is:

<?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/nfeDownloadNF">
            <cUF>31</cUF>
            <versaoDados>3.10</versaoDados>
        </nfeCabecMsg>
    </soap:Header>
    <soap:Body>
        <nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF">
            <downloadNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="3.10">
                <tpAmb>1</tpAmb>
                <xServ>DOWNLOAD NFE</xServ>
                <CNPJ>[NUMERO DO CNPJ]</CNPJ>
                <chNFe>[CHAVE DA NOTA FISCAL]</chNFe>
            </downloadNFe>
        </nfeDadosMsg>
    </soap:Body>
</soap:Envelope>

I've removed all the spaces as requested (I already use some other services successfully)

request.Method = "POST";
request.ContentType = "text/xml";
request.ContentLength = byteData.Length;

The certificate I'm sure is correct too.

I emphasize that I can consume other services.

Service WSDL

<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF">
    <wsdl:types>
        <s:schema elementFormDefault="qualified" targetNamespace="http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF">
            <s:element name="nfeDadosMsg">
                <s:complexType mixed="true">
                    <s:sequence>
                        <s:any/>
                    </s:sequence>
                </s:complexType>
            </s:element>
            <s:element name="nfeDownloadNFResult">
                <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="versaoDados" type="s:string"/>
                    <s:element minOccurs="0" maxOccurs="1" name="cUF" type="s:string"/>
                </s:sequence>
                <s:anyAttribute/>
            </s:complexType>
        </s:schema>
    </wsdl:types>
    <wsdl:message name="nfeDownloadNFSoapIn">
        <wsdl:part name="nfeDadosMsg" element="tns:nfeDadosMsg"/>
    </wsdl:message>
    <wsdl:message name="nfeDownloadNFSoapOut">
        <wsdl:part name="nfeDownloadNFResult" element="tns:nfeDownloadNFResult"/>
    </wsdl:message>
    <wsdl:message name="nfeDownloadNFnfeCabecMsg">
        <wsdl:part name="nfeCabecMsg" element="tns:nfeCabecMsg"/>
    </wsdl:message>
    <wsdl:portType name="NfeDownloadNFSoap">
        <wsdl:operation name="nfeDownloadNF">
            <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
                Serviço destinado ao atendimento de solicitações de download de Notas Fiscais Eletrônicas por seus destinatários.
            </wsdl:documentation>
            <wsdl:input message="tns:nfeDownloadNFSoapIn"/>
            <wsdl:output message="tns:nfeDownloadNFSoapOut"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="NfeDownloadNFSoap" type="tns:NfeDownloadNFSoap">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="nfeDownloadNF">
            <soap:operation soapAction="http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF/nfeDownloadNF" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
                <soap:header message="tns:nfeDownloadNFnfeCabecMsg" part="nfeCabecMsg" use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="NfeDownloadNFSoap12" type="tns:NfeDownloadNFSoap">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="nfeDownloadNF">
            <soap12:operation soapAction="http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF/nfeDownloadNF" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
                <soap12:header message="tns:nfeDownloadNFnfeCabecMsg" part="nfeCabecMsg" use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="NfeDownloadNF">
        <wsdl:port name="NfeDownloadNFSoap" binding="tns:NfeDownloadNFSoap">
            <soap:address location="https://www.sefazvirtual.fazenda.gov.br/NfeDownloadNF/NfeDownloadNF.asmx"/>
        </wsdl:port>
        <wsdl:port name="NfeDownloadNFSoap12" binding="tns:NfeDownloadNFSoap12">
            <soap12:address location="https://www.sefazvirtual.fazenda.gov.br/NfeDownloadNF/NfeDownloadNF.asmx"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

INFORMATION ON SERVICE DOCUMENTATION

POST /NfeDownloadNF/NfeDownloadNF.asmx HTTP/1.1
Host: www.sefazvirtual.fazenda.gov.br
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF/nfeDownloadNF"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF">
      <versaoDados>string</versaoDados>
      <cUF>string</cUF>
    </nfeCabecMsg>
  </soap:Header>
  <soap:Body>
    <nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF">xml</nfeDadosMsg>
  </soap:Body>
</soap:Envelope>

Could someone tell me the error?

    
asked by anonymous 03.11.2015 / 17:40

1 answer

3

I managed to make it work, I will report here all the problems I had to help someone who is in the same situation.

Note It's best to use the URL: link

The message should read as follows:

<?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/NfeDownloadNF">
            <cUF>31</cUF>
            <versaoDados>1.00</versaoDados>
        </nfeCabecMsg>
    </soap:Header>
    <soap:Body>
        <nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF">
            <downloadNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00">
                <tpAmb>1</tpAmb>
                <xServ>DOWNLOAD NFE</xServ>
                <CNPJ>[CNPJ]</CNPJ>
                <chNFe>[CHAVE]</chNFe>
            </downloadNFe>
        </nfeDadosMsg>
    </soap:Body>
</soap:Envelope>

The main points are:

  • Today 04/11/2015 the service is in version 1.00, different from what is indicated in the site of the farm

  • The namespace should be link and not link

  • Do not forget to remove the blank characters, the message can not have any formatting characters.

  • You will only be able to download notes that have user manifestation.

04.11.2015 / 13:40