Magento 2.2.5 – Fix SOAP-ERROR Parsing WSDL

magento-2.2.5magento2soapweb serviceswsdl

Every time I run this script. I get an error.
I placed this file in the root directory of my magento.

soapexample.php:

<?php 

error_reporting(E_ALL); 

ini_set('display_errors', 1);

require('vendor/zendframework/zend-server/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client/Common.php');

$wsdlurl = 'https://www.chemcopharmacy.com/soap/default?wsdl&services=salesOrderRepositoryV1';

$token = 'u46losnl6ia01ctmxxxxxxxxxxxxx'; //access token


$opts = ['http' => ['header' => "Authorization: Bearer ".$token]]; 
$context = stream_context_create($opts); //$arguments = $serviceArgs = 
$serviceArgs = array('searchCriteria'=> 
    array('filterGroups' => 
        array ('filters' =>
            array('field' =>'increment_id',
                  'value' => '000000002' , 
                  'condition_type' => 'eq')
            )
     ) ); 
 $soapClient = new \Zend\Soap\Client($wsdlurl);
 $soapClient->setSoapVersion(SOAP_1_2); 
 $soapClient->setStreamContext($context);
 $result = $soapClient->salesOrderRepositoryV1GetList($serviceArgs);

//array('searchCriteria' => $serviceArgs)); //$result = $soapClient->customerCustomerRepositoryV1GetById(array('customerId' => 1));

Error:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing 
WSDL: Couldn't load from 'https://www.chemcopharmacy.com/soap/default? 
wsdl&services=salesOrderRepositoryV1' : failed to load external entity 
"https://www.chemcopharmacy.com/soap/default? 
wsdl&services=salesOrderRepositoryV1" in 
/var/www/html/chemcopharmacy/vendor/zendframework/zend- 
soap/src/Client/Common.php:33 Stack trace: #0 
/var/www/html/chemcopharmacy/vendor/zendframework/zend- 
soap/src/Client/Common.php(33): SoapClient- 
>SoapClient('https://www.che...', Array) #1 
/var/www/html/chemcopharmacy/vendor/zendframework/zend- 
soap/src/Client.php(1070): Zend\Soap\Client\Common->__construct(Array, 
'https://www.che...', Array) #2 
/var/www/html/chemcopharmacy/vendor/zendframework/zend- 
soap/src/Client.php(1245): Zend\Soap\Client->initSoapClientObject() #3 
/var/www/html/chemcopharmacy/vendor/zendframework/zend- 
soap/src/Client.php(1156): Zend\Soap\Client->getSoapClient() #4 
/var/www/html/chemcopharmacy/soapexample2.php(29): Zend\Soap\Client- 
>__call('salesOrderRepos. in 
/var/www/html/chemcopharmacy/vendor/zendframework/zend- 
soap/src/Client/Common.php on line 33

What I have done?

  • I have edited the /etc/hosts file and added the MY.IP.ADDRESS DOMAIN.COM

  • I have also set necessary setting in php.ini files for soap like

    extension=php_soap.dll;
    extension=php_openssl.dll;

Best Answer

I tried the SOAP Web Services on my local host and it was working fine. The reason why the Magento 2 was not able to give a response to the request was because it was not able to verify SSL Certificates enabled on the site.

The way I resolved it was to allow self signed SSL verification:

$opts = [
    'http' =>
     [
         'header' => "Authorization: Bearer ".$token
        ],
'ssl' => [
    'allow_self_signed' => true , 
    'verify_peer' => false, 
    'verify_peer_name' => false]
];
$context = stream_context_create($opts);

I hope it helps. ;)

Related Topic