SOAP E-social Request Template

Asked

Viewed 607 times

0

Come on, guys, I’m having serious trouble executing the SOAP request on E-social servers.

This is my code:

    $pfx = file_get_contents($pfx);
    $certificate = Certificate::readPfx($pfx, $pass);

    $wsdl = 'https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/enviarloteeventos/WsEnviarLoteEventos.svc?WSDL';
    $arquivo_xml = file_get_contents(ROOT_APP_CONTROLLER."rh/esocial/teste.xml");

    $action = 'EnviarLoteEventos';
    $operation = '';
    $parameters = [];
    $namespaces = [];
    $request = htmlentities($arquivo_xml, ENT_COMPAT, 'UTF-8');
    $soapheader = null;

    try {
        $soap = new \NFePHP\Common\Soap\SoapCurl($certificate);
        $response = $soap->send($wsdl, $operation, $action, SOAP_1_1, $parameters, $namespaces, $request, $soapheader);
        print_r($response);     

    } catch (Exception $e) {
        print_r($e->getMessage());
    }  

It presents me with the following error in returning Try catch:

An error occurred while trying to communication via soap,  [https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/enviarloteeventos/WsEnviarLoteEventos.svc?WSDL]HTTP/1.1 100 Continue

HTTP/1.1 415 Cannot process the message because the content type 'application/soap+xml;charset=utf-8;action=EnviarLoteEventos' was not the expected type 'text/xml; charset=utf-8'.
Cache-Control: private
Server: Microsoft-IIS/8.5
Set-Cookie: ASP.NET_SessionId=kfr2yuodygwpey5lnoronfzi; path=/; HttpOnly
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 27 Apr 2018 12:15:18 GMT
Content-Length: 0

Then I imagined that I would just change the header of the request to text/xml; charset=utf-8', but when I change it presents me the following error:

An error occurred while trying to communication via soap,  [https://webservices.producaorestrita.esocial.gov.br/servicos/empregador/enviarloteeventos/WsEnviarLoteEventos.svc?WSDL]HTTP/1.1 100 Continue

HTTP/1.1 400 Bad Request
Cache-Control: private
Server: Microsoft-IIS/8.5
Set-Cookie: ASP.NET_SessionId=k0ii5ocr23zuujcgcuw0xfl2; path=/; HttpOnly
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 27 Apr 2018 12:18:40 GMT
Content-Length: 0

I’ve been banging my head on this for three days, if anyone knows how to fix it, please help me!!!

1 answer

0

The message is very clear, you are sending a Content-type invalid, different from what the service is expecting.

Try to add the Content-type correct in the request header, something like this:

$soapheader = array("Content-type: text/xml;charset=utf-8",
                    "Accept: text/xml");

Browser other questions tagged

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