I have a problem communicating with the eSocial webService, my certificate is correct, but still can not establish a secure connection, it displays the following message: "Error making HTTP request for
Gabriel, I believe you were unable to access the service because the URL you are using is incorrect. When you add the ? Wsdl parameter at the end of the service URL, you are requesting the eSocial service's WSDL, which is the contract service. That is, this URL you posted would be the one you would use to add the reference to the service inside Visual Studio, and the same URL without parameter ? Wsdl would be the one you would use to actually access the service.
So, to access the service, the URL should be this:
In addition, according to the eSocial Developer's Guide v1.6.3, page 83, item '7.9. You should also install on the machine that will access the Chain of Certificates service issued on 06/02/2017 by Serpro, which are 3 certificates that can be obtained at this address:
> According to the 02.03 item of the eSocial Portal FAQ page, certificates must be installed in the order that they are arranged on this Serpro page, and:
The Certification Authority Brazilian root v5 must be installed in the root CA repository. The SERPRO Certification Authority v4 and SERPRO Certification Authority Final v5 must be installed in the intermediate CA repository.
Remember that it is also necessary to have a valid digital certificate (A1 or A3, e-CNPJ or e-CPF) installed on the computer that will access the web service, which must be used to access the service. One tip: When I started the tests with eSocial, I was almost a week banging my head to get the first access, when I finally discovered that in my case (e-CNPJ A1), it was necessary to select the Mark this key how to exportable and store ) and install my certificate in the store Personal / em>), Current User and Current User
Regarding the code used to access the service (I do not know if you are already doing so, because you have not posted any code snippets), you should configure the binding service (I've used% (for HTTPS) and ClientCredentialType = Certificate (to specify a certificate), something like this:
> var urlServicoEnvio = @"https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/enviarloteeventos/WsEnviarLoteEventos.svc";
var address = new EndpointAddress(urlServicoEnvio);
var binding = new BasicHttpsBinding(); //Disponível desde .NET Framework 4.5
// ou:
//var binding = new BasicHttpBinding(BasicHttpsSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var wsClient = new WsEnviar.ServicoEnviarLoteEventosClient(binding, address);
wsClient.ClientCredentials.ClientCertificate.Certificate = x509Cert;
var retornoEnvioXElement = wsClient.EnviarLoteEventos(loteEventosXDoc.Root);
wsClient.Close();
As for the BasicHttpBinding
class used in code, it was created by Visual Studio when adding a Service Reference , using a URL similar to the one you tried to use to access the service (with the difference that I used the singleWsdl parameter instead of ? wsdl ):
In VS it is also possible to add a reference to the service by directly using the WsSubmitEvents-v1_1_0.wsdl file available in the eSocial Communication Package (latest version 1.4.1) , which can be found on the technical documentation page of the eSocial Portal.
This tool, Add Service Reference , will create a client class to consume the web service, in the case of the BasicHttpsBinding
sample, which inherits the System.ServiceModel.ClientBase class .
You can also use the svcutil.exe command line tool, which will likewise create a client class inheriting the System.ServiceModel.ClientBase class. Alternatively, you can also use the older wsdl.exe command line tool for ASMX-based .NET Framework 2 time services that will also create a client class, but this time inheriting the System.Web.Services.Protocols.SoapHttpClientProtocol class. But in that case the code to consume the service would be a bit different.
Following all these steps, access to the eSocial web service should work.