php Soap wsdl connection with certificate

Asked

Viewed 604 times

0

Zero experience with Soap/wsdl and need to consume a web service through php and Soap/wsdl with certificate and private key.

Searching, I found this code:

$local_cert = "../cert.pem";
$local_priv = "../private.key";
$wsdl = "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl";
// editado
$location = "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo";

$options = array(    
    'keep_alive'    => true,
    'trace'         => true,
    'location'      => $location, // editado
    'local_cert'    => $local_cert,
    'local_priv'    => $local_priv,
    'passphrase'    => '1234567',
    'cache_wsdl'    => WSDL_CACHE_NONE
);

try {
    $soapClient = new SoapClient($wsdl, $options);
} catch(Exception $e) {
    var_dump($e);
}

When connecting, it shows the following error:

Object(Soapfault)#2 (9) { ["message":protected]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn’t load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load External Entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(65) "/home/Storage/a/7f/23/openselos/public_html/Soap/teste/client.php" ["line":protected]=> int(50) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(65) "/home/Storage/a/7f/23/openselos/public_html/Soap/teste/client.php" ["line"]=> int(50) ["Function"]=> string(10) "Soapclient" ["class"]=> string(10) "Soapclient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(78) "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" [1]=> array(6) { ["keep_alive"]=> bool(true) ["trace"]=> bool(true) ["local_cert"]=> string(11) ".. /cert.pem" ["local_priv"]=> string(14) ".. /private.key" ["passphrase"]=> string(7) "1234567" ["cache_wsdl"]=> int(0) } } } ["Previous":"Exception":private]=> NULL ["faultstring"]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn’t load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load External Entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["faultcode"]=> string(4) "WSDL" }

Error after the edited:

Object(Soapfault)#2 (9) { ["message":protected]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn’t load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load External Entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(65) "/home/Storage/a/7f/23/openselos/public_html/Soap/teste/client.php" ["line":protected]=> int(52) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(65) "/home/Storage/a/7f/23/openselos/public_html/Soap/teste/client.php" ["line"]=> int(52) ["Function"]=> string(10) "Soapclient" ["class"]=> string(10) "Soapclient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(78) "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" [1]=> array(7) { ["keep_alive"]=> bool(true) ["trace"]=> bool(true) ["Location"]=> string(73) "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo" ["local_cert"]=> string(11) ".. /cert.pem" ["local_priv"]=> string(14) ".. /private.key" ["passphrase"]=> string(7) "1234567" ["cache_wsdl"]=> int(0) } } } ["Previous":"Exception":private]=> NULL ["faultstring"]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn’t load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load External Entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["faultcode"]=> string(4) "WSDL" }

The certificate previously used was with some kind of problem, because it gave error in Soapui and after using another certificate, everything worked. This new certificate, has been converted to . pem with private key included, but still remains with error.

// link wsdl
$wsdl = "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl";

// certificado
$cert = "Opensystem_A1.pem";
$cert_senha = 'senha';

$param = array(    
     'keep_alive'    => true,
     'trace'         => true,
     'local_cert'    => $cert,
     'passphrase'    => $cert_senha,
     'cache_wsdl'    => WSDL_CACHE_NONE
);

try {
    $soapClient = new SoapClient($wsdl, $param);
} catch(Exception $e) {
    var_dump($e);
}

The mistake:

Object(Soapfault)#3 (9) { ["message":protected]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn’t load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load External Entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(65) "/home/Storage/a/7f/23/openselos/public_html/Soap/teste/client.php" ["line":protected]=> int(52) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(65) "/home/Storage/a/7f/23/openselos/public_html/Soap/teste/client.php" ["line"]=> int(52) ["Function"]=> string(10) "Soapclient" ["class"]=> string(10) "Soapclient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(78) "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" [1]=> array(5) { ["keep_alive"]=> bool(true) ["trace"]=> bool(true) ["local_cert"]=> string(17) "Opensystem_a1.pem" ["passphrase"]=> string(5) "password" ["cache_wsdl"]=> int(0) } } } } ["Previous":"Exception":private]=> NULL ["faultstring"]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn’t load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load External Entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["faultcode"]=> string(4) "WSDL" }

  • Is the certificate and key accessible with the path you placed (.../cert.pem ../private.key)? The password is correct?

  • @Marabesi, yes, everything ok, way, password. :/

  • Maybe this link can help you https://stackoverflow.com/a/11681353/2258921

  • But in this connection only has the certificate, no private key...

  • Have you tried sending the contents of the private key instead of the file path? It can be with file_get_contents to test

  • I went to check the password and found that it was incorrect... however, it continues with the same error. I added 'Location' and the contents of the key with file_get_contents and continues with the error, I added above.

  • Apparently the certificate was in some kind of trouble. I tested it on Soapui, and it was a mistake. I contacted the support of the service who recommended using another certificate and did not give error, it worked well, however in php script still with error. I edited the question with the new certificate (only .pem with included key) and error.

Show 2 more comments
No answers

Browser other questions tagged

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