4
votes

I'm using XAMPP on Windows and try to work with PHP soap extension SoapClient. I'm trying to load a WSDL file hosted in HTTPS site using the following code

<?php
    $myClient=new SoapClient("https://smi.sp.f-secure.com/smi/5.1/services/EchoService?wsdl");
?>

I get the following error:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://smi.sp.f-secure.com/smi/5.1/services/EchoService?wsdl' : failed to load external entity "https://smi.sp.f-secure.com/smi/5.1/services/EchoService?wsdl" in C:\xampp\htdocs\dev\w3schools\soapClient\index.php:2 Stack trace:
#0 C:\xampp\htdocs\dev\w3schools\soapClient\index.php(2): SoapClient->SoapClient('https://smi.sp....')
#1 {main} thrown in C:\xampp\htdocs\dev\w3schools\soapClient\index.php on line 2

Now I took a network capture during the request and saw that HTTPS communication does not work OK on SSL Level. Wireshark shows a packet on Server Key Exchange my workstation responds with:

TLSv1 Record Layer: Alert (Level: Fatal, Description: Certificate Unknown)

Wireshark Screenshot

Using nuSOAP client or soapUI utility from the same computer, I'm able to connect to the service normally. So no certificate problems I guess.

So definately it's something with SOAP extension and SSL communication. Can anyone help? Give hints what to look for?

4
I wouldn't wish SOAP on my worst enemy.dan-klasson
Thank you Len_D. My extension=php_openssl.dll is enabled, and OpenSSL version is 1.0.1i. It must be something related to PHP SOAP related, because when I use nuSOAP it is able to work with the very same HTTPS service.killerchip
Same problem on PHP >= 7step

4 Answers

0
votes

it has to do with this change in php 5.6: http://php.net/manual/en/migration56.openssl.php

I have the same trouble on Windows with php 5.6 and it works fine on Linux with php 5.6.

You can use the function openssl_get_cert_locations to see what are the certificate locations.

So far I wasn't able to find a solution.

9
votes

To workaround this error you could deactivate the SSL certificate validation. But keep in mind, that this should only be done for test cases, because this makes your connection insecure!

You can pass a stream context when instantiating the SoapClient like this:

<?php
$myClient = new SoapClient("https://smi.sp.f-secure.com/smi/5.1/services/EchoService?wsdl", [
    'stream_context' => stream_context_create([
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ]),
]);

If you have a valid certificate but it is selfsigned, there is another solution (more secure):

<?php
$myClient = new SoapClient("https://smi.sp.f-secure.com/smi/5.1/services/EchoService?wsdl", [
    'stream_context' => stream_context_create([
        'ssl' => [
            'allow_self_signed' => true,
        ],
    ]),
]);
0
votes

PHP Soap Extension, SoapClient supports HTTPS connections.

My problem is definately a bug, I'm dealing with XAMPP 5.6.3 (PHP 5.6.3, Apache 2.4.10)

When I deploy XAMPP 5.5.19 (PHP 5.5.19, Apache 2.4.10) my code works just fine. The WSDL file is downloaded from HTTPS site and processed normally.

0
votes

Having the same problem with PHP 5.6.9 on a Windows server which formerly when using PHP 5.3.3 had no problem with this. Checked every setting recommended (extensions being loaded), you know what, afterwards I found out there is no problem when running the script on the command line...

Additional: When trying to catch the SOAP exception, it fails. I hoped in this version the age old https bug concerning the SOAP client not taking the socket timeout into account was fixed, but the problems with the SOAP client seem to be ongoing.