1
I’m trying to consume the web service Query to Event Identifiers, but I get this return:
<?xml version="1.0"?>
<eSocial xmlns="http://www.esocial.gov.br/schema/consulta/identificadores-eventos/retorno/v1_0_0">
<retornoConsultaIdentificadoresEvts>
<status>
<cdResposta>402</cdResposta>
<descResposta>Solicitação inválida. Redefina sua consulta</descResposta>
</status>
</retornoConsultaIdentificadoresEvts>
</eSocial>
I am sending the following XML:
<?xml version="1.0" encoding="utf-8"?>
<eSocial xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.esocial.gov.br/schema/consulta/identificadores-eventos/empregador/v1_0_0">
<consultaIdentificadoresEvts>
<ideEmpregador>
<tpInsc>1</tpInsc>
<nrInsc>00000000000000</nrInsc>
</ideEmpregador>
<consultaEvtsEmpregador>
<tpEvt>S-1000</tpEvt>
<perApur>2018</perApur>
</consultaEvtsEmpregador>
</consultaIdentificadoresEvts>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<DigestValue>7vfFTl1HHrHL5V/fTfL5Bmq3gUOarDwzGPhBCwrDKQ0=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>...</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>...</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
</eSocial>
This is the code that generated the XML above (I hid the CNPJ):
static void Main(string[] args)
{
// Cria o objeto
ServicoConsultarIdentificadoresEventosClient client = new ServicoConsultarIdentificadoresEventosClient();
Modelos.ConsultaIdentificadoresEventos.eSocial esocial = new Modelos.ConsultaIdentificadoresEventos.eSocial();
esocial.consultaIdentificadoresEvts = new eSocialConsultaIdentificadoresEvts();
esocial.consultaIdentificadoresEvts.ideEmpregador = new TIdeEmpregador();
esocial.consultaIdentificadoresEvts.ideEmpregador.tpInsc = 1;
esocial.consultaIdentificadoresEvts.ideEmpregador.nrInsc = "00000000000000";
esocial.consultaIdentificadoresEvts.consultaEvtsEmpregador = new TConsultaEventosEmpregador();
esocial.consultaIdentificadoresEvts.consultaEvtsEmpregador.perApur = "2018";
esocial.consultaIdentificadoresEvts.consultaEvtsEmpregador.tpEvt = "S-1000";
// Carrega o certificado
X509Certificate2 certificado = new X509Certificate2();
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
certificado = store.Certificates[1];
// Serializa o objeto
var xml = Serialize(esocial);
// Adiciona o certificado
SignXmlDoc(xml, certificado);
// Gera o arquivo XML no disco
XmlSerializer xs = new XmlSerializer(typeof(XmlDocument));
TextWriter txtWriter = new StreamWriter(@"C:\\temp\\Serialization.xml");
xs.Serialize(txtWriter, xml);
txtWriter.Close();
// Define o certificado que será usado na chamada do WS
client.ClientCredentials.ClientCertificate.Certificate = certificado;
// Converte de document para element
XDocument linqXml = XDocument.Parse(xml.OuterXml);
// Chama o serviço enviando o XML
var retorno = client.ConsultarIdentificadoresEventosEmpregador(linqXml.Root);
// Deserializa o objeto
Modelos.RetornoIndeitificadoresEventos.eSocial deserialized = new Modelos.RetornoIndeitificadoresEventos.eSocial();
StringReader reader = new StringReader(retorno.ToString());
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Modelos.RetornoIndeitificadoresEventos.eSocial));
deserialized = (Modelos.RetornoIndeitificadoresEventos.eSocial)xmlSerializer.Deserialize(reader);
client.Close();
}
I used xsd.exe and svcutil to generate the codes.
Someone has already obtained this error and knows how to solve or get more details?
It seems to me that you are not sending the request in the format or with valid values.
– Leandro Angelo
Did this employer already have something sent in 2018? Try removing the attributes
xmlns:xsi
andxmlns:xsd
tageSocial
, before signing, to see if anything changes; see item 3 of that reply: https://answall.com/a/348662/86952– Pedro Gaspar
Yes, the employer sent this event last year. @Pedrogaspar I used your codes to serialize and remove the 2 attributes, but keeps returning me the same message.
– Igor Brandão