Reputation: 377
My problem is very common. I read almost all topics on stackoverflow about this issue, but still can not do thing work. My code is :
ini_set("soap.wsdl_cache", "0");
ini_set("soap.wsdl_cache_enabled", "0");
$proxy = new SoapClient('http://Myhostname/api/soap?wsdl');
I had this error :
Error WSDL: SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://Myhostname/api/soap?wsdl' : failed to load external entity
"http://Myhostname/api/soap?wsdl"
In the browser the URL
http://Myhostname/api/soap?wsdl
works great (returns an xml response)
I try this code to see if PHP can reach this URL :
if (file_get_contents('http://Myhostname/api/soap?wsdl') === false) {
echo "ERROR: file_get_contents <br/>";
}
It displays me my error "ERROR: file_get_contents", so it does not work. On the forums I saw that to solve this problem I must add hostname into OS "hosts" file. So I did it. In my hosts file I added this line 127.0.0.1 Myhostname
But it still does not work. Then I changed URL in my code to
http://localhost/Myhostname/api/soap?wsdl
but it does not work either.
I tried another solution I found on the internet. For some people it worked. In my URL I changed '?' character to '.'. So my new URL became
http://localhost/Myhostname/api/soap.wsdl
but it does not work either.
I saw official SOAP doc! And tried to create SoapClient object in different way (with options like 'proxy_host' and 'proxy_port'). But this did not help me.
It's my second day I try to solve this problem, but I can not. I am doing my internship, I do not have a lot of experience, so maybe I did not try solutions I found correctly. Maybe someone can help. I would be very pleased.
Upvotes: 17
Views: 25937
Reputation: 203
I tried the SOAP Web Services
on my local host and it was working fine. The reason why the Magento
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. ;)
Upvotes: 0
Reputation: 13009
instead of $proxy = new SoapClient('http://Myhostname/api/soap?wsdl'
);
try $proxy = new SoapClient(WSDLFILENAME);
where WSDLFILENAME is the OS name of the WSDL file.
This has the additional benefit of making one client-server roundtrip less.
Upvotes: 1
Reputation: 943
Few steps to check
Have a ping to Myhostname. It would give the ip. Use ip instead and see
Check if the services are enabled
S0AP,
php_openssl,
openssl,
curl
Hope you would get it :)
Upvotes: 3
Reputation: 480
I have the similar problem, I solve it uncommenting -MultiViews from .htaccess file, and later from Apache configuration of local website.
My working Apache configuration is:
<Directory /var/www/>
Options Indexes FollowSymLinks -MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
You can try also url:
http://localhost/Myhostname/api.php?type=soap&wsdl
if you use community edition.
Upvotes: 2