Glorious Kale
Glorious Kale

Reputation: 1313

PHP SoapClient Doesn't Retrieve WSDL with Client Certificate

Other similar questions have not helped me resolve this.

I have to retrieve a WSDL file using a client certificate + private key combination from my webserver calling another external SOAP API.

$wsdl     = 'https://www.example.com?wsdl';
$endpoint = 'https://www.example.com';

$sslContext = stream_context_create($contextOptions);

$options = [
    'local_cert'                => '/var/www/combo.pem',
    'passphrase'                => 'Pass1',
    'cache_wsdl'                => WSDL_CACHE_MEMORY,
    'trace'                     => 1,
    'stream_context'            => stream_context_create([
        'ssl' => [
            'ciphers'           => 'RC4-SHA',
            'verify_peer'       => false,
            'verify_peer_name'  => false,
            'allow_self_signed' => true
        ]
    ])
];

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

The error I'm getting is: SOAP-ERROR: Parsing WSDL: Couldn't load from '..domain..' : failed to load external entity "..domain..?wsdl"

I tried numerous settings and none of them made any difference to this response. I tried no settings, empty array.

What has worked:

phpinfo() returns SoapClient is enabled, OpenSSL is enabled. What else could I try or check?

Upvotes: 1

Views: 1024

Answers (2)

Farzan
Farzan

Reputation: 935

I wanted to comment this but based on others' suggestions of using file_get_contents and your reply mentioning that it returned false, I'm now kind of sure it's more of a connection problem. Please check followings:

  1. It's obvious that your actual $wsdl value is different than what is posted but please make sure that .com?wsdl is not happening in your code. it should be .com/?wsdl.
  2. Check your DNS settings. A lookup through dnslookup can help identify problem.
  3. Make sure date & time setting of server is correct. It can lead to SSL errors.

If none of above helped. You might consider downloading WSDL content with other tools (such as cURL) and on different machines to identify the cause of problem.

Upvotes: 1

NPULSENET
NPULSENET

Reputation: 190

SOAP error could come from invalid character encoding or maybe some HTTP header missing like 'User-Agent' when you query the remote server.

Try to adding User-Agent to options like the sample below.

$options = array(
    'http' => array(
        'user_agent' => 'PHP_Embedded_Soap_Client'
    )
);

PS: I would not recommend to strict ciphers to: RC4-SHA

Upvotes: 1

Related Questions