Error 242 while consuming Nfedownloadnf

Asked

Viewed 1,677 times

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 obtained the following error:

ERROR: 242 Reason: Bounce: Non-existent nfeCabecMsg element in 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’ve been sending 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 removed all spaces as requested (already consume some other services successfully)

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

The certificate I’m sure is correct too.

Rebound that I can consume other services.

WSDL of the service

<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 IN THE 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 point out the mistake?

  • This web service is where, specifically? Look here and I didn’t find.

  • This is one of the SPED Webservices, specifically the service responsible for downloading a specific invoice for the key.

  • So, I tried to get the WSDL to check if your message is correct, but I couldn’t. From which site you got this link?

  • Thank you so much for your help. The link I took some examples from the web, but the WSDL can be obtained from the address : https://www.sefazvirtual.fazenda.gov.br/NfeDownloadNF/NfeDownloadNF.asmx?wsdl However if you cannot access, may be some restriction on certificates that must be installed in the browser I will copy the contents below

  • That’s what I tried. Error 403. It makes no sense to require a certificate to get the WSDL.

  • It doesn’t really make any sense, but it seems that this is what they do.... : ( yet I copied the contents of the page with the WSDL to my question.

  • 2

    Looking, without testing, the only thing I see different in header of soap message is the namespace, who is http://www.portalfiscal.inf.br/nfe/wsdl/nfeDownloadNF while it should be http://www.portalfiscal.inf.br/nfe/wsdl/NfeDownloadNF.

  • Bruno César really, the problem was not solved, but the namespace was wrong. The mistake changed I am treating.

Show 3 more comments

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 is better to use the URL: https://www.nfe.fazenda.gov.br/NfeDownloadNF/NfeDownloadNF.asmx

The Message should be 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:

Browser other questions tagged

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