1
I am trying to query the Receiptent2099, however I do not know the correct form in the documentation speaks the URL and the method and also the parameters, I created an xml with the parameters and I am trying to send the request, but I always get this error:
Remote server returned an error: (400) Incorrect Request
What I am doing wrong or someone has an example of this C query#.
public string Consulta(X509Certificate2 cert)
{
//string xmlRequisicaoSOAP = MontarXmlRequisicao();
var xmlz = @"wwwroot\reinf\R_2099\consultaFechamento\ReinfLayout_R_2099_Consulta.xml";
var xml = new XmlDocument();
xml.Load(xmlz);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://preprodefdreinf.receita.fazenda.gov.br/wsreinf/ConsultasReinf.svc");
request.Headers.Add("SOAPAction", "http://sped.fazenda.gov.br/ConsultasReinf/ConsultaReciboEvento2099");
request.ContentType = "text/xml;charset=\"utf-8\"";
request.Accept = "text/xml";
request.Method = "POST";
if (cert != null)
request.ClientCertificates.Add(cert);
if (this.TimeOutEmSegundos > 0)
request.Timeout = this.TimeOutEmSegundos * 1000;
this.UltimaRequisicao = xml.OuterXml;
using (Stream stream = request.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stream))
{
stmw.Write(xml);
}
}
try
{
WebResponse webresponse = request.GetResponse();
HttpWebResponse response = (HttpWebResponse)webresponse;
//if(response.StatusCode == HttpStatusCode.OK)
using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
{
string result = responseReader.ReadToEnd();
return result;
}
}
catch (WebException wex)
{
string mensagemSubjacente = ObterMensagemSubjacente(wex);
string msg = string.Format("{1}{0}Detalhes subjacentes: {2}",
System.Environment.NewLine, wex.Message, mensagemSubjacente);
throw new InvalidOperationException(msg);
//throw new ExcecaoComunicacaoREINF(msg, wex, xmlRequisicaoSOAP);
}
catch (Exception ex)
{
throw ex;
// throw new ExcecaoComunicacaoREINF(ex.Message, ex, xmlRequisicaoSOAP);
}
}
Thank you, I added here according to your example by wsdl, and managed to perform the query
– Fernando josé