How to reference the webservices of eSocial by Visual Studio?

Asked

Viewed 926 times

4

I already followed the instructions of this question read, reread, and repeated the tutorial by Pedro Gaspar. And I can’t get eSocial webservices referenced by Visual Studio. What I’ve done so far is:

  • I installed the chains of certificates, both the 15/01/2014 and the 06/02/2017 in the correct sequence.
  • I installed the strings by placing all the certificates in the Root repository of Local Machine
  • I installed the chains placing only the Brazilian Root Certification Authority v5 in the Root repository and the others in the intermediate repository.
  • I installed the Certificate (valid, not expired and with correct password) of my client in the Personal repository (On Machine Location and Current User)

I can access the web service addresses through the browser and the lock is green. When I try to add service by the visual studio the following occurs:

inserir a descrição da imagem aqui

When making a "Web Reference", the following happens: inserir a descrição da imagem aqui

See that it accesses WS (because in the browser also accesses) however, still appears Forbidden.

I tried to do by SVCUTIL.EXE and the result was the following:

C:\WINDOWS\system32>svcutil https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/consultarloteeventos/WsConsultarLoteEventos.svc?singleWsdl
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.6.1055.0]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from 'https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/consultarloteeventos/WsConsultarLoteEventos.svc?singleWsdl' using WS-Metadata Exchange or DISCO.
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.6.1055.0]
Copyright (c) Microsoft Corporation.  All rights reserved.

Error: Cannot obtain Metadata from   https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/consultarloteeventos/WsConsultarLoteEventos.svc?singleWsdl

If this is a Windows (R) Communication Foundation service to which you have 
access, please check that you have enabled metadata publishing at the 
specified address.  For help enabling metadata publishing, please refer to 
the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.

WS-Metadata Exchange Error
URI: https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/consultarloteeventos/WsConsultarLoteEventos.svc?singleWsdl

Metadata contains a reference that cannot be resolved: 'https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/consultarloteeventos/WsConsultarLoteEventos.svc?singleWsdl'.

The HTTP request was forbidden with client authentication scheme 'Anonymous'.

The remote server returned an error: (403) Forbidden.

HTTP GET Error
URI: https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/consultarloteeventos/WsConsultarLoteEventos.svc?singleWsdl

There was an error downloading 'https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/consultarloteeventos/WsConsultarLoteEventos.svc?singleWsdl'.

The request failed with HTTP status 403: Forbidden.

If you would like more help, type "svcutil /?"

C:\WINDOWS\system32>

The messages caught my attention Error: Cannot obtain Metadata... , Metadata contains a reference that cannot be resolved and The HTTP request was forbidden with client authentication scheme 'Anonymous'

My possibilities are exhausted, I don’t know what else to test. Someone has a suggestion?

2 answers

3


Ewerton, the easiest way is for you to access the URL in the browser:

https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/enviarloteeventos/WsEnviarLoteEventos.svc?singleWsdl

right-click on the page, click on Save as... and save a file with extension .wsdl on the local machine, and then use that WSDL file (Web Services Description Language) to add the reference to the service in Visual Studio. I think I did so at the time.

The other way (that I learned now, hehe), for you to be able to add the service using the URL directly is a little more complicated, because Visual Studio has to know the certificate that must be used to access a given address.

For this you must access the Windows Control Panel and do this way (my Windows is in English, so I don’t know what the Portuguese names are like): Control Panel > User Accounts > Credential Manager > Manage Windows Credentials, in the section Certificate-Based Credentials you click on the link Add a Certificate-based Credential.

You then infoma the domain webservices.producaorestrita.esocial.gov.br in the field Internet or network address, and click on the button Select Certificate.

I learned that tip now with that OS responseEN:

https://stackoverflow.com/a/27435343/8133067

If you have Visual Studio open, exit and enter again. After that Visual Studio must recognize which certificate to use to access the eSocial service (in the Restricted Production environment).

  • Yes... this is new for me, by the way, it’s new the possibility to put a physical path there in the "Add Service Reference" window, I always thought it could only be URL, I put the WSDL path and it worked! Thank you

  • Poxa Ewerton, and the worst thing is that this detail (of using a local path), and also the response of Rovann Linhalis, were written there in my tutorial, which you read and reread several times! But, I know how it is, sometimes despair hits and the answer is in our face and we do not see. ;-)

1

In the Technical Documentation made available, has the "Communication Package".

Inside it, you have the WSDL to use the Webservice. In Visual Studio, just add the "Webreference" the same way you are doing, but pointing to the file on your local machine.

inserir a descrição da imagem aqui

  • 1

    Thank you Rovnann, I didn’t even imagine that it was possible to reference using the path of a physical file, I always thought a URL was required.

Browser other questions tagged

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