The webservice Downloadnfe has been disabled as per NT 2014.002.v.1.02.
The webservice you should use is:
https://www1.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx
In this webservice you perform the recipient’s manifestation and in the next query it returns the full XML of Nfe.
Follow link to the technical note: Technical Note 2014.002 - v1.02
I made a very simple example, put a button and a textbox in a form. I added the webservice address in the visual studio project as Servicereference, so the visual studio already generates the necessary class. Follows code:
Do not forget to replace the code data with your company data, and without reading the technical note there is no way you understand the return of the webservice.
private void button1_Click(object sender, EventArgs e)
{
NFeDistribuicaoDFeSoapClient consDFe = new NFeDistribuicaoDFeSoapClient();
consDFe.ClientCredentials.ClientCertificate.Certificate = ObterDoRepositorio();
distDFeInt distDfe = new distDFeInt();
distDfe.versao = TVerDistDFe.Item100;
distDfe.tpAmb = TAmb.Item1;
distDfe.cUFAutor = TCodUfIBGE.Item50;
distDfe.ItemElementName = ItemChoiceType.CNPJ;
distDfe.Item = "000000000000000";
distDFeIntDistNSU distNSU = new distDFeIntDistNSU();
distNSU.ultNSU = "000000000";
distDfe.Item1 = distNSU;
string xmlEnvio = SerializeToString(distDfe);
var removeq1 = new string[] { ":q1", "q1:" };
foreach (var item in removeq1)
{
xmlEnvio = xmlEnvio.Replace(item, string.Empty);
}
XElement xml = XElement.Parse(xmlEnvio);
var asd = consDFe.nfeDistDFeInteresse(xml);
textBox1.Text = asd.ToString();
}
public static X509Certificate2 ObterDoRepositorio()
{
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.MaxAllowed);
var collection = store.Certificates;
var fcollection = collection.Find(X509FindType.FindByTimeValid, DateTime.Now, true);
var scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Certificados válidos:", "Selecione o certificado que deseja usar",
X509SelectionFlag.SingleSelection);
if (scollection.Count == 0)
{
throw new Exception("Nenhum certificado foi selecionado!");
}
store.Close();
return scollection[0];
}
public static string SerializeToString(Object value)
{
var emptyNamepsaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
var serializer = new XmlSerializer(value.GetType());
var settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
using (var stream = new StringWriter())
using (var writer = XmlWriter.Create(stream, settings))
{
serializer.Serialize(writer, value, emptyNamepsaces);
return stream.ToString();
}
}
Link on github
which UF and which URL you are using ?
– Rovann Linhalis
You have just posted the same question: https://answall.com/questions/229137/download-nfe-nfephp , it may be some change of revenue service, it must have something to do with this http://www.contabeis.com.br/noticias/35193/cfc-alert_overdosionstax-electronic/
– AnthraxisBR
UF - SP URL as reported in the documentation: http://hom.nfe.fazenda.gov.br/portal/webServices.aspx?tipConteudo=Wak0FwB7dKs=#AN
– Thiago Motta Barboza
Look, it looks like the service is paralyzed. I don’t know if you have any experience with the IRS, but this is very common.
– Jéf Bueno
The worst is that on the SEFAZ service availability page appears as if everything is working normally.
– Jéf Bueno
I had this problem with Sefaz some time ago and it was due to the modification of the Consulted method...
– JcSaint
@Jcsaint you have the solution used for this problem?
– Thiago Motta Barboza