Magento – Magento 2 SOAP api not working

magento-2.1soapsoap-api-v2

I am not able to access product details using SOAP API while i call api url i am getting Error:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://127.0.0.1/test_magento_2/soap/default?wsdl&services=catalogProductTypeListV1' : failed to load external entity "http://127.0.0.1/test_magento_2/soap/default?wsdl&services=catalogProductTypeListV1" in /opt/lampp/htdocs/test_magento_2/api.php:59 Stack trace: #0 /opt/lampp/htdocs/test_magento_2/api.php(59): SoapClient->SoapClient('http://127.0.0....', Array) #1 {main} thrown in /opt/lampp/htdocs/test_magento_2/api.php on line 59

I am using magento 2.1.5
and I have also set necessary setting in php.ini files for soap like
extension=php_soap.dll
extension=php_openssl.dll
i am facing this issue in my local system and in live server.

My code for call SOAP API:

$token = 'kxij7mg931mxc3h2hy7dyvxm9m3fy4k4';
$opts = ['http' => ['header' => "Authorization: Bearer " . $token]];
$wsdlUrl = 'http://127.0.0.1/test_magento_2/soap/default?wsdl&services=catalogProductTypeListV1';
$context = stream_context_create($opts);
$soapClient = new SoapClient($wsdlUrl, ['version' => SOAP_1_2, 'context' => $context]);
$soapResponse = $soapClient->__getFunctions();
var_dump($soapResponse);

Best Answer

Try commenting out the foreach in vendor/magento/framework/Webapi/Authorization.php ( line 36 to 40 )

Should look like this:

public function isAllowed($aclResources)
{
    //foreach ($aclResources as $resource) {
    //    if (!$this->authorization->isAllowed($resource)) {
    //        return false;
    //    }
    //}
    return true;
}

I had the same problem, this fixed it.